【发布时间】:2020-07-27 21:02:41
【问题描述】:
我在 DataGridTemplateColumn 中有一个标签,我使用触发器确保在选择行时前景为白色(蓝色)。 选择行后,但没有聚焦DataGrid,它仍然是白色的;这是有道理的,因为它仍然被选中。
但我想在 IsSelected 和网格处于非活动状态时将前景设为黑色。
这里是样式和列
感谢您的帮助。
<Style x:Key="DataGridLabelStyle" TargetType="Label" BasedOn="{StaticResource DataGridControlStyle}" >
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding >
<MultiBinding Converter="{StaticResource BooleanAndConverter}">
<Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType={x:Type DataGridRow}}" />
<Binding Path="IsKeyboardFocused" RelativeSource="{RelativeSource AncestorType={x:Type DataGrid}}" Converter="{StaticResource NegateBooleanConverter}" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="White" />
</DataTrigger>
</Style.Triggers>
</Style>
<DataGridTemplateColumn Header="Date">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding TransactionDate}" Style="{StaticResource DataGridLabelStyle}" ContentStringFormat="yyyy-MM-dd" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding TransactionDate}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
【问题讨论】:
标签: wpf xaml triggers datagrid wpf-style