3

我正在尝试IsSelectionActive使用 WPF DataGrid:

<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <ContentPresenter />
                <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsSelectionActive" Value="False" />
                            <Condition Property="IsSelected" Value="True" />
                            <!--<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, Path=IsSelected}" Value="True" />
                            <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=IsKeyboardFocusWithin}" Value="True" />-->
                        </MultiTrigger.Conditions>

基本上,当网格失去焦点,但选择仍然存在时,我想应用一些样式。

不幸的是,IsSelectionActive由于某种原因,它会引发 WPF 数据网格中不存在的错误。

4

1 回答 1

4

IsSelectionActive 是一个附加属性。我认为你需要使用

<Condition Property="Selector.IsSelectionActive" Value="False" /> 

这种简化的风格对我有用:

<Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}">
    <Style.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="Selector.IsSelectionActive" Value="False" />
                <Condition Property="IsSelected" Value="True" />
            </MultiTrigger.Conditions>
            <Setter Property="Background" Value="Red"/>
        </MultiTrigger>
    </Style.Triggers>
</Style>
于 2012-05-27T13:18:29.133 回答