title: Dynamic DataGrid Columns and Content in XAML
body: <p>I have the following XAML code:</p>
  
  <pre><code>&lt;TabControl Grid.Row="1" x:Name="tabs" ItemsSource="{Binding}"&gt;
      &lt;TabControl.ItemContainerStyle&gt;
          &lt;Style TargetType="{x:Type TabItem}"&gt;
              &lt;Setter Property="Header" Value="{Binding Name}" /&gt;
              &lt;Setter Property="Visibility" Value="{Binding Visibility}" /&gt;
          &lt;/Style&gt;
      &lt;/TabControl.ItemContainerStyle&gt;
      &lt;TabControl.ContentTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;Grid&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition Height="Auto" /&gt;
                      &lt;RowDefinition Height="1*" /&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;WrapPanel Grid.Row="0"&gt;
                      &lt;ComboBox VerticalAlignment="Center" HorizontalAlignment="Left" Width="100"  ItemTemplate="{StaticResource     CCCItemTemplate}" ItemsSource="{Binding Subtypes}" /&gt;
                      &lt;ComboBox VerticalAlignment="Center" HorizontalAlignment="Left" Width="100"  ItemTemplate="{StaticResource CCCFileItemTemplate}" ItemsSource="{Binding Files}" /&gt;
                  &lt;/WrapPanel&gt;
                  &lt;DataGrid Grid.Row="1" ItemsSource="{Binding Path=Files}" /&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
      &lt;/TabControl.ContentTemplate&gt;
  &lt;/TabControl&gt;
  </code></pre>
  
  <p>Where the tabs themselves are being added dynamically via XAML with <code>tabs.DataContext = fileTypes;</code>.
  Each tab has it's own DataGrid, associated with a "FileType" class.
  Each FileType class has a <code>public ObservableCollection&lt;SecondaryFile&gt; Files { get; set; } = new ObservableCollection&lt;SecondaryFile&gt;();</code>, and each SecondaryFile has</p>
  
  <pre><code>public ArrayList Columns { get; set; } = new ArrayList();
  ...
  public string[][] data { get; set; };
  </code></pre>
  
  <p>Is there anyway to bind the columns and data to the grid via XAML?
  Keep in mind the TabItems and matching DataGrids are dynamic themselves, as is the number of columns and their contents.</p>
  
  <p>I tried giving the grids a name in a dynamic fashion so I can access it programmatically, but to no avail.</p>
  
  <p>Any suggestions would be more than welcome!</p>
  
  <p>Thanks!</p>