How can I make columns coloring in DataGrid if I also want use AlternatingRowBackground property? I have some ideas, but it doesn't work :(.
<de:DataGrid Name="dataGrid1"
AlternationCount="2"
AlternatingRowBackground="Salmon"
>
<de:DataGrid.Columns>
<de:DataGridTextColumn Binding="{Binding Path=Phrase}"
Header="Phrase">
<de:DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="Green"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="Red"></Setter>
</Trigger>
</Style.Triggers>
<开发者_运维知识库;/Style>
</de:DataGridTextColumn.ElementStyle>
</de:DataGridTextColumn>
</de:DataGrid.Columns>
</de:DataGrid>
Maybe somebody knows working solution? Thanks.
You are searching AlternationIndex property in the wrong control. This property belongs to DataGridRow.
<DataGrid ItemsSource="{Binding}" AlternationCount="2" AutoGenerateColumns="False" AlternatingRowBackground="Salmon">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Phrase}" Header="Phrase">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding AlternationIndex, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="0">
<Setter Property="Background" Value="Green"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding AlternationIndex, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="1">
<Setter Property="Background" Value="Red"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
精彩评论