如果column为false,如何创建一个xml样式来交替使用rowbackground颜色2行

时间:2022-11-05 11:48:08

Alternating Colors on Rows Example

行上的交替颜色示例

Hi Everyone, I wanted to know if there was someone who can help me put things together. I'm trying to create a style for my datagrid. I want the table rows to act the way I've represented them to act in the image. So basically I have a column that is a bool. When it's true I want to row to be a certain color. Then when it's not false I want the colors alternating every 2 rows until it encounters another row where the bool is true.

大家好,我想知道是否有人能帮助我把事情放在一起。我正在尝试为我的数据网格创建一个样式。我希望表行按照我表示的方式行事,以便在图像中起作用。所以基本上我有一个bool的列。如果这是真的我想排成一定的颜色。然后,当它不是假的时候,我希望每2行交替颜色,直到它遇到bool为真的另一行。

I've been messing with triggers, multitdatatriggers, but still no luck.

我一直在搞乱触发器,multitdatatriggers,但仍然没有运气。

1 个解决方案

#1


0  

Style in App.xml

App.xml中的样式

<Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                <Setter Property="Foreground" Value="Red" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                <Setter Property="Foreground" Value="Red" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="2">
                <Setter Property="Foreground" Value="Blue" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="3">
                <Setter Property="Foreground" Value="Blue" />
            </Trigger>
            <DataTrigger Binding="{Binding isLeague}" Value="True">
                <Setter Property="Foreground" Value="White"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

Grid on MyControl.xaml

MyControl.xaml上的网格

<DataGrid Name="DG1" AlternationCount="4">

#1


0  

Style in App.xml

App.xml中的样式

<Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                <Setter Property="Foreground" Value="Red" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                <Setter Property="Foreground" Value="Red" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="2">
                <Setter Property="Foreground" Value="Blue" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="3">
                <Setter Property="Foreground" Value="Blue" />
            </Trigger>
            <DataTrigger Binding="{Binding isLeague}" Value="True">
                <Setter Property="Foreground" Value="White"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

Grid on MyControl.xaml

MyControl.xaml上的网格

<DataGrid Name="DG1" AlternationCount="4">