title: Dynamically adding buttons to ItemsControl
body: <p>I have a issue that i want your inouts on. I have a outer grid and it has two columns. On first column i am using a ItemsControl that is bind to a a view model (This view model is for dynamically creating buttons). I have a wrap pannel templete define for the Item templete. The 2nd column is for a list box.</p>
  
  <p>I create the objects for the buttons in the view model and that gets binded to the view.The requiremnet is that if the window hieight fits then all buttons should appear in a single colum (one below the other) else it should come in two columns.</p>
  
  <p>If one column</p>
  
  <p>1<br/> 
  2<br/>
  3<br/>
  4</p>
  
  <p>If Two Columns :</p>
  
  <p>1  2<br/>
  3  4</p>
  
  <p>The code i have is given below :</p>
  
  <p>ItemsControl:</p>
  
  <pre><code>&lt;Grid&gt;...
  &lt;ItemsControl ItemsSource="{Binding buttonsViewModelColl}"
             ItemsPanel="{StaticResource WrapPanelTemplateA}"
           ItemTemplate="{StaticResource ButtonsDataTempleteA}" Width="{Binding ActualWidth, ElementName=&lt;OuterGrid&gt;}" Grid.Row="2" HorizontalAlignment="Center"/&gt;     
  &lt;/Grid&gt;
  </code></pre>
  
  <p>WrapPannelTemplete:</p>
  
  <pre><code>&lt;ItemsPanelTemplate x:Key="WrapPanelTemplate"&gt;
               &lt;WrapPanel/&gt;
           &lt;/ItemsPanelTemplate&gt;
  </code></pre>
  
  <p>DataTempleteForButton :</p>
  
  <pre><code>&lt;DataTemplate x:Key="ButtonsDataTempleteA"&gt;
               &lt;Button 
                              Content="{Binding Path=Text}" 
                              IsEnabled="{Binding Path=IsEnabled}"
                               Style="{StaticResource StyleButtonA}" 
                              FontFamily="Segoe UI Semibold"
                               HorizontalAlignment="Left" /&gt;
           &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>The problem is that on rendering only one or two buttons are visible. If i set teh WrapPannel Orientation to vertical all comes but they donot wrap automatically. Only if i drap and extend teh width of window all are visible. Also teh sequence is not correct :</p>
  
  <p>They come as :</p>
  
  <p>A C<br/>
  B D</p>
  
  <p>Any Ideas.</p>
  
  <p>Another question : Is there a way i can increase the width of the inner grid column based on an outer grid height at runtime in XAML ?</p>