GridRow模板内AlternatingRowBackgrou

GridRow模板内AlternatingRowBackgrou

本文介绍了我如何覆盖DataGridRow模板内AlternatingRowBackground?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建与AlternatingRowBackground产权行一个DataGrid。然而,在这些行中的数据必须被修正,需要一些时间。

I'm creating a DataGrid with rows with AlternatingRowBackground property. However, the data in the rows must be amended and that takes some time.

我试图让行的背景颜色出现浅灰色,而他们正在初始化。下面是我在RowTemplate正在做的:

I'm trying to make the background color of the rows appear light gray while they are initializing. Here's what I'm doing in the RowTemplate:

<ControlTemplate.Triggers>
    <DataTrigger Binding="{Binding Initialized}" Value="False">
        <Setter Property="Background" Value="LightGray"/>
    </DataTrigger>
</ControlTemplate.Triggers>



但是,这并不对仍然在AlternatingRowBackground指定的颜色奇数行工作。

But this does not work for the odd rows which still have the color specified in AlternatingRowBackground.

我如何覆盖此所以它不会被初始化所有的行出现浅灰色的?

How do I overwrite this so all rows which are not initialized appear light gray?

推荐答案

我有同样的问题,并为我工作。下一页:
将在风格AlternatingRowBackground,但不是在DataGrid

I had the same problem and worked for me next:Set the AlternatingRowBackground in the style, but not in the DataGrid.

    <Grid.Resources>
        <Style x:Key="dg" TargetType="DataGrid">
            <Setter Property="AlternatingRowBackground" Value="Orange"/>
            <Setter Property="AutoGenerateColumns" Value="False"/>
        </Style>
    </Grid.Resources>
    <DataGrid ItemsSource="{Binding Source={StaticResource one}, Path=Persons}" Style="{StaticResource dg}">
        <DataGrid.Columns>
            <DataGridTextColumn Width="*" Header="Name" Binding="{Binding Path=Name}"/>
        </DataGrid.Columns>
        <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Mature}" Value="True">
                        <Setter Property="Background" Value="LightGray"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>
    </DataGrid>

这篇关于我如何覆盖DataGridRow模板内AlternatingRowBackground?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:52