title: In WPF, how can I add a border to a control in code behind?
body: <p>In my XAML I want to dynamically generate a ListBox with the following:</p>
  
  <pre><code>&lt;ListBox Name="MainListBox"&gt;
    &lt;Border Style="{DynamicResource ListBoxItemRoundedBorder}"&gt;
       &lt;ListBoxItem &gt;
          &lt;TextBlock&gt;
            Some Text Here
          &lt;/TextBlock&gt;
       &lt;/ListBoxItem&gt;
     &lt;/Border&gt;
  
    &lt;Border Style="{DynamicResource ListBoxItemRoundedBorder}"&gt;
       &lt;ListBoxItem &gt;
          &lt;TextBlock&gt;
            Some Text Here
          &lt;/TextBlock&gt;
       &lt;/ListBoxItem&gt;
     &lt;/Border&gt;
  
    &lt;Border Style="{DynamicResource ListBoxItemRoundedBorder}"&gt;
       &lt;ListBoxItem &gt;
          &lt;TextBlock&gt;
            Some Text Here
          &lt;/TextBlock&gt;
       &lt;/ListBoxItem&gt;
     &lt;/Border&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>I want to add items to this listbox via code behind.  How can I add the item and the border via code behind.  I can add the list box items easy enough but can't seem to figure out the border:</p>
  
  <pre><code> For Each s As String in MyArray
     Dim lbi as New ListBoxItem()
     Dim tb as New TextBlock()
     tb.Text = s
     lbi.content = tb
     MainListBox.Items.Add(lbi)
   Next
  </code></pre>
  
  <p>Edit:  To clear up any confusion I want a border around each of the ListBox Items.  I've updated the XAML - effectively I want to render that XAML dynamically, or equivalent, via code behind.  I already have the border style defined.</p>