Zdravim,
potrebuji poradit. Mam univerzalni tabulku pro ruzna data. Data dostanu az za behu programu, takze tabulka musi sama automaticky generovat sloupce. Vsechno funguje do doby, nez se pokusim zmenit Template nektereho sloupce. Nevim jak spravne nastavit Binding na sloupec v DataTable.
XAML tabulka:
<DataGrid x:Name="mainDataGrid" ItemsSource="{Binding Data}" AutoGeneratingColumn="DataGrid_AutoGeneratingColumn" />
C# kod:
public DataTable Data
{
get { return data; }
set
{
data = value;
NotifyPropertyChanged("Data");
}
}
private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.PropertyType == typeof(DateTime))
{
var templateColumn = new DataGridTemplateColumn();
templateColumn.CellTemplate = (DataTemplate)Resources["DateTemplate"];
templateColumn.CellEditingTemplate =(DataTemplate)Resources["DateEditTemplate"];
e.Column = templateColumn;
}
}
Problemova cast:
<UserControl.Resources>
<DataTemplate x:Key="DateTemplate">
<TextBlock Text="{Binding ???}" />
</DataTemplate>
<DataTemplate x:Key="DateEditTemplate">
<DatePicker SelectedDate="{Binding ???}" />
</DataTemplate>
</UserControl.Resources>
Jak nastavit Binding aby to fungovalo? Pokud nevytvarim vlastni sloupec (DataGridTemplateColumn) pri automatickem generovani, tak vse funguje, takze to nejak musi jit udelat.