how to bind data each colmuns in DataGriTemplateColumns?

23 views Asked by At

i tried to make some table.

with datagrid, some template and obejct.

but i have some problem

( .cs)
class X{
  public int id{get;set;}
  ...
}
class Y{
  public int id{get;set;}
  ...
}
class A{
  public X x {get;set;}
  public Y y {get;set;}
}

....
A a = new A();
// a.add some datas

datagrid.ItemSource = a;

( .xaml)
    <DataTemplate x:Key="T">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="{Binding id}" Grid.Column="0"/>
            <TextBlock Text="{Binding .}" Grid.Column="2"/>
        </Grid>
    </DataTemplate>
------------------------------------------------------------------

        <DataGrid x:Name="datagrid" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTemplateColumn CellTemplate="{StaticResource T}"/>  <!-- X object column -->
                <DataGridTemplateColumn CellTemplate="{StaticResource T}"/>  <!-- Y object column -->
            </DataGrid.Columns>
        </DataGrid>

i don't know how to bind different data each columns.

each columns just bounded object A.

and i will add columns about other objects(A's property.). so i don't want modify datatemplate

what code should i add

0

There are 0 answers