DataGrid ItemsSource is bound 2 times

Nov 8, 2010 at 12:44 PM

Hello, can't find a solution, so I ask here.

 

I have a model class MyClassA with getter and setter properties, one of these properties is an ObservableCollection<MyClassB> bCollection holding items of an other own type MyClassB. The model itself is used in XAML like this:

<TabItem.Resources>
  <model:MyClassA x:Key="classA" />
</TabItem.Resources>

Now I am trying to set the ItemsSource property of a DataGrid. I haven't found, how to get it through a binding of classA as a StaticResource - is it possible? So I set the DataGrid's DataContext to bCollection in code-behind and my XAML looks like this:

<DataGrid ItemsSource="{Binding}" >
  <DataGrid.Columns>
    <DataGridTemplateColumn Header="Year">
      <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding Year}" />
        </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
  </DataGrid.Columns>
</DataGrid>

And I see the data from bCollection , but I get it twice - first time in my defined DataGrid.Columns and then all MyClassB properties are shown as columns again...