【发布时间】:2021-12-29 04:46:20
【问题描述】:
我有一个数据网格模板列,我在其中更改文本块“MyTextBlockRotationVersion”后面代码中的文本颜色。我正在尝试使用文本颜色更改来更改单元格的背景颜色,以便当它从单元格模板变为单元格编辑模板时,反之亦然,红色背景仍然存在。不知道为什么触发器没有将背景变为红色。现在文本颜色会改变,但背景不会。在进入单元编辑模板并返回单元模板后,我失去了颜色变化。
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="MyTextBlockRotationVersion" Text="{Binding RotationVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" MaxWidth="70"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsEditing" Value="True" />
</Trigger>
<Trigger x:Name="MyTextBlockRotationVersion" Property="Foreground" Value="Red">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGridTemplateColumn.CellStyle>
【问题讨论】: