Home Forums WPF controls Xceed DataGrid for WPF Alternate row color

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • HanzieV
    Participant
    Post count: 13
    #44042 |

    Hi,

    I’m trying to apply an alternate row color to my datagid. Here’s the XAML I’m using:

    <!–Toolkit DataGrid–>
    <Style x:Key=”DefaultDataGridControlStyle” TargetType=”datagridtoolkit:DataGridControl”>
    <Setter Property=”Background” Value=”DarkGreen”/>
    <Setter Property=”AlternationCount” Value=”2″/>
    </Style>
    <Style TargetType=”datagridtoolkit:DataGridControl” BasedOn=”{StaticResource DefaultDataGridControlStyle}”/>

    <!–Toolkit DataGridRow–>
    <Style x:Key=”DefaultDataRowStyle” TargetType=”datagridtoolkit:DataRow”>
    <!–<Setter Property=”Background” Value=”White”/>–>
    <Style.Triggers>
    <Trigger Property=”IsSelected” Value=”True”>
    <Setter Property=”BorderBrush” Value=”Aqua” />
    <Setter Property=”BorderThickness” Value=”3″ />
    <Setter Property=”FontWeight” Value=”Bold” />
    <Setter Property=”FontSize” Value=”16″ />
    </Trigger>
    <Trigger Property=”ItemsControl.AlternationIndex” Value=”0″>
    <Setter Property=”Background” Value=”Orange”></Setter>
    </Trigger>
    <Trigger Property=”ItemsControl.AlternationIndex” Value=”1″>
    <Setter Property=”Background” Value=”Red”></Setter>
    </Trigger>
    </Style.Triggers>
    </Style>
    <Style TargetType=”datagridtoolkit:DataRow” BasedOn=”{StaticResource DefaultDataRowStyle }”/>

    Can anyone explain why this is not working ?
    Applying these styles to the default DataGrid control works fine …

    Best regards,
    Hans

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    You may use the below style to customize the DataRow’s alternating color:

    <Style TargetType=”xcdg:DataRow”>
    <Style.Triggers>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
    <Condition Binding=”{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.DataGridContext).CurrentItem, Converter={StaticResource nullToBooleanConverter}}”
    Value=”False” />
    <Condition Binding=”{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridVirtualizingPanel.ItemIndex), Converter={x:Static xcdg:IndexToOddConverter.Singleton}}”
    Value=”True” />
    </MultiDataTrigger.Conditions>
    <Setter Property=”Background” Value=”Azure”>

    </Setter>
    </MultiDataTrigger>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
    <Condition Binding=”{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.DataGridContext).CurrentItem, Converter={StaticResource nullToBooleanConverter}}”
    Value=”False” />
    <Condition Binding=”{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridVirtualizingPanel.ItemIndex), Converter={x:Static xcdg:IndexToOddConverter.Singleton}}”
    Value=”false” />
    </MultiDataTrigger.Conditions>
    <Setter Property=”Background” Value=”Gray”>
    </Setter>
    </MultiDataTrigger>

    </Style.Triggers>

    </Style>

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.