0
我需要創建dataGrid,他的每個列都包含textBox和comboBox。
但我的dataGrid列是在應用程序的開始時創建的 - 通過讀取一些配置文件...應用程序知道要創建多少個列以及每個列的標題名稱是什麼。是否有可能更改DataGrid列的動態列?
我甚至不知道如何創建每個這些動態將包含文本框和組合框(我想從某種程度上XAML做到這一點>
有人能幫助我的可能性?
我需要創建dataGrid,他的每個列都包含textBox和comboBox。
但我的dataGrid列是在應用程序的開始時創建的 - 通過讀取一些配置文件...應用程序知道要創建多少個列以及每個列的標題名稱是什麼。是否有可能更改DataGrid列的動態列?
我甚至不知道如何創建每個這些動態將包含文本框和組合框(我想從某種程度上XAML做到這一點>
有人能幫助我的可能性?
你需要使用DataGridTemplateColumn並綁定文本框的文本和組合框的ItemsSource屬性accordinglein爲了使用自定義模板。
<DataGrid ItemsSource="{Binding ContentsToTransfer}">
<DataGridTemplateColumn Header="Category">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Text="{Binding Category}"/>
<ComboBox ItemsSource="{Binding Categories}"></ComboBox>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid>
這link可以幫助你充分理解它。
爲什麼不使用DataTemplate for dataGridColumn? – Akansha