I am trying to create DataTemplateone that can be split for all columns GridView, which has columns created dynamically (via code).
I would like to create DataTemplateas a resource in XAML, and not completely in the code, but I cannot figure out how to make the bindings work correctly.
The following is the closest I could come up with (but does not work):
<DataTemplate x:Key="ListViewCellTemplate">
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type GridViewColumn}}}" />
</DataTemplate>
This template is assigned as CellTemplateeach column as follows:
BindableDataTable table = this.DataContext as BindableDataTable;
foreach (BindableDataColumn c in table.Columns)
{
GridViewColumn col = new GridViewColumn();
col.Header = c.ColumnName;
col.CellTemplate = this.FindResource("ListViewCellTemplate") as DataTemplate;
v.Columns.Add(col);
}
source
share