2

我正在尝试根据行的类型以及是否选择它来为数据网格中的不同行设置不同的颜色:

<Style TargetType="DataGridCell" x:Key="ActiveCellStyle">
    <Setter Property="Foreground" Value="Black"/>
    <Style.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                 <Condition Binding="{Binding Type}" Value="0"/>
                 <Condition Property="IsSelected" Value="False"/>
            </MultiDataTrigger.Conditions>      
            <Setter Property="Background" Value="#FFDFE6ED"/>
        </MultiDataTrigger>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                 <Condition Binding="{Binding Type}" Value="0"/>
                 <Condition Property="IsSelected" Value="True"/>
            </MultiDataTrigger.Conditions>      
            <Setter Property="Background" Value="#FF6CAFF1"/>
        </MultiDataTrigger>
        ...
    </Style.Triggers>
</Style>

当我运行它时,我得到 ArgumentException: key cannot be null。

我怎样才能解决这个问题?

4

1 回答 1

1

With MultiTriggeryou useProperty和 with MultiDataTriggeryou use Binding,你不能把它们结合起来。所以改变

<Condition Property="IsSelected"

<Condition Binding="{Binding RelativeSource={RelativeSource Self},
                             Path=IsSelected}"

它应该可以工作

<Style TargetType="DataGridCell" x:Key="ActiveCellStyle">
    <Setter Property="Foreground" Value="Black"/>
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding Type}" Value="0"/>
                    <Condition Binding="{Binding RelativeSource={RelativeSource Self},
                                                 Path=IsSelected}"
                                       Value="False"/>
                </MultiDataTrigger.Conditions>
                <Setter Property="Background" Value="#FFDFE6ED"/>
            </MultiDataTrigger>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Type}" Value="0"/>
                <Condition Binding="{Binding RelativeSource={RelativeSource Self},
                                             Path=IsSelected}"
                           Value="True"/>
            </MultiDataTrigger.Conditions>
            <Setter Property="Background" Value="#FF6CAFF1"/>
        </MultiDataTrigger>
    </Style.Triggers>
</Style>
于 2012-06-09T13:16:31.687 回答