[英]WPF DataGrid with cell style — different cell style in same column
[英]Datagrid Template Column Cell Style Trigger not working
我有一個數據網格模板列,我在其中更改文本塊“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>
我認為您不能從另一個DataTemplate
(或ControlTemplate
)中訪問元素
還要按名稱訪問特定元素,您要使用SourceName
而不是x:Name
( x:Name
命名觸發器)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.