I am trying to create a DataGrid by datatemplates. The reason is I want the columns to be dynamically created but all in xaml and not in code behind. I get a List based on which I want to create my grid columns in xaml.
class GridColumnElement
{
public string HeaderCaption { get; set; }
public string PropertyName { get; set; }
public Type PropertyType { get; set; }
public double Width { get; set; }
public bool CheckbocColumn { get; set; }
}
Is it possible by any means to generate columns in xaml for a datagrid by data/control/content templating ?
Something in the lines of what I tried for this... but not possible.
<Usercontrol.Resources>
<CollectionViewSource x:Key="bindingSource" Source="{Binding BindingItems}"/>
// BindingItems is my actual binding source
<DataTemplate DataType="{x:Type CustomTypes:GridColumnElement}">
// trying to generate columns, matching with property name like this, but cannot since
// datagrid columns cant be generated this way.
<DataGridTextColumn Binding="{Want to mention gridcolumnelement.PropertyName here}"> </DataGridTextColumn>
</DataGrid.Columns>
</DataTemplate>
<Usercontrol.Resources>
UserControl:
-------------
<DataGrid ItemsSource={Binding GridColumnElementCollection} />
Is there any other ways of achieving this all in xaml ?
Thanks, Mani