WPF DataGrid AlternatingRowBackground和RowStyle优先级

use*_*042 10 wpf wpfdatagrid

如何让我RowStyle获得申请AlternatingRowBackground?我想要的物品,有IsOrange作为trueOrange背景,无论交替行背景,这是不是这种情况目前的.

XAML:

<DataGrid Name="g"
    AlternatingRowBackground="Blue" 
    AlternationCount="2" 
    ...
    SelectionMode="Single">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsOrange}" Value="Y">
                    <Setter Property="Background" Value="Orange" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
    ...
</DataGrid>
Run Code Online (Sandbox Code Playgroud)

LPL*_*LPL 16

这不是一个错误.在a中,Style您无法覆盖交替行的本地值集.这就是为什么这不起作用

<DataGrid AlternatingRowBackground="Blue"
Run Code Online (Sandbox Code Playgroud)

但如果你设置AlternatingRowBackgroundStyle你可以

<DataGrid.Style>
    <Style TargetType="DataGrid">
        <Setter Property="AlternatingRowBackground" Value="Blue"/>
    </Style>
</DataGrid.Style>
Run Code Online (Sandbox Code Playgroud)

感谢这个答案.