title: C# Add items from listbox to Usercontrol
body: <p>I am a new programmer. I will try to explain as well as I can. I am programming a tool in WPF. I made a usercontrol as follows.</p>
  
  <p><a href="http://i.stack.imgur.com/fkBki.png" rel="nofollow">User control</a></p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="30"&gt;&lt;/ColumnDefinition&gt;
          &lt;ColumnDefinition Width="150"&gt;&lt;/ColumnDefinition&gt;
          &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
          &lt;ColumnDefinition Width="50"&gt;&lt;/ColumnDefinition&gt;
          &lt;ColumnDefinition Width="30"&gt;&lt;/ColumnDefinition&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Button x:Name="DelOutConBT" Margin="5" Content="X" Click=" Delete ConnSet"&gt;&lt;/Button&gt;
      &lt;Label x:Name="OutConLB" Grid.Column="1" &gt;&lt;/Label&gt;
      &lt;ComboBox x:Name="InConComB" Grid.Column="2"&gt;&lt;/ComboBox&gt;
      &lt;TextBox x:Name="ConnValueTX" Grid.Column="3" Margin="5"&gt;&lt;/TextBox&gt;
      &lt;Button Grid.Column="4" Margin="5" Content="&gt;&gt;"&gt;&lt;/Button&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>In the mainwindow, I already programmed a listbox and a tab. The listbox will be filled some items with running a Python script. </p>
  
  <p>Now, I want to enable user to add a usercontrol by select a item in the listbox and click button in the mainwindow. </p>
  
  <p>My question is how can the usercontrol load information automatically when it is added. I want the Label in the Usercontrol shows the item selected from the listbox, and the Combobox shows all items in the Listbox. </p>
  
  <p>Then, by clicking the button">>" in the usercontrol, the data in the usercontrol can be saved to a class or sth else. Because I will use all data filled in usercontrols with another Python script. </p>
  
  <p>This is what I programed to add the user control to main window.</p>
  
  <p>Mainwindow.xaml.cs</p>
  
  <pre><code>private void ConSel_Click(object sender, RoutedEventArgs e)
  {
      if (ListB.SelectedItem != null)
      {
          string name = ((ListBoxItem)ListB.SelectedItem).Name;                
          ConnSet CSobj = new ConnSet();
          StkConn.Children.Add(CSobj);                
      }                        
  }
  </code></pre>