I have a DataGrid binded to a DataTable that I've called "GridCollection" :
<!--DataGrid-->
<DataGrid Name="DataGrid" ItemsSource="{Binding GridCollection}" >
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<ComboBox ItemsSource="{Binding SelectionOptions}">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Caption, Mode=TwoWay}" Value="ShowComboBox">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
I want to be able to dynamically update the DataGrid Column Cell Template to display comboboxes.
I've tried to achieve this by adding a DataTrigger binded to a property of the DataTable column ("Caption"), and then updating the Visibility of the combobox accordingly.
My understanding is that the DataContext in this case is the DataTable's Columns.
I have tried setting the "Caption" property of the DataTable's Columns to match the value speicified in the DataTrigger ("ShowComboBox") :
ViewModel.GridCollection.Columns[index].Caption = "ShowComboBox";
After confirming that this line of code is being executed and that the Caption property is being updated, this is still making no change to the DataGrid. No columns are showing a combo box.
I'm not sure if there is a problem with the binding, or if it is something else.
Any help is appreciated!