I would like to be able to programmatically create DataGridTemplateColumns based on my data source. For example, if my source has a date in a particular column I would like to be able to utilize a Datepicker control. I know this is easily accomplished with xaml and a DataGridTemplateColumn at design-time, however, how would I accomplish this at run-time?
Is my best option xamlreader.load or a more traditional route like:
Dim TempCol As Microsoft.Windows.Controls.DataGridTemplateColumn
I have not had any success with the latter.
Thanks.
-Paul
Edit: This is the code I attempted to use:
Dim TempCol As New Microsoft.Windows.Controls.DataGridTemplateColumn
TempCol.CellEditingTemplate = DataTemplate.Equals(DatePicker)
I receive DatePicker is a type and cannot be used as an expression.
I am basiing this on the WPF Toolkit demo. http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-datagrid-feature-walkthrough.aspx
<dg:DataGridTemplateColumn Header="Date" MinWidth="100">
<dg:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<dg:DatePicker SelectedDate="{Binding Date}" SelectedDateFormat="Short" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellEditingTemplate>
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Date, StringFormat=d}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
Thanks!