I have two cell template, one is for "ReadOnly" the other is for "CellEditing". And a button is binding a command to switch a variable (IsEditable) to be true/false. When I click the button, the style does not change until double click the cell.
My question is, how to change DataGrid Cell Style dynamically without double click the cell.
My XAML:
<DataTemplate x:Key="ReadOnlyTemplate">
<TextBox Text="{Binding ProductionName}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Background" Value="Black"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</TextBox.Style>
</TextBox>
</DataTemplate>
<DataTemplate x:Key="CellEditingTemplate">
<TextBox Text="{Binding ProductionName}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Background" Value="Black"/>
<Setter Property="Foreground" Value="White"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsEditable}" Value="True">
<Setter Property="IsEnabled" Value="True"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DataTemplate>
...
<DataGridTemplateColumn Header="Name" CellTemplate="{StaticResource ReadOnlyTemplate}" CellEditingTemplate="{StaticResource CellEditingTemplate}"/>