Home Forums WPF controls Xceed DataGrid for WPF Alternating row colors

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22532 |

    Maybe I’ve missed a post on this, or some documentation, but is it possible to style the alternating rows? Even something as simple as just the background color would be great.

    Imported from legacy forums. Posted by Brett (had 5298 views)

    Xceed Support
    Member
    Post count: 5658

    We have currently no “simple” way of doing this alternating row thing. It is however on our todo list.

    If you “must” tackle this immediatly, then I advise placing a DataTrigger on the DataRow style and in the trigger bind to Self (RelativeSource={RelativeSource Self} and place a converter on the binding that would extract the item index from the container ( using the ItemContainerGenerator for the DataGridControl ).

    Imported from legacy forums. Posted by Marcus [Xceed] (had 297 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok, thanks. Doesn’t sound too bad with a converter, I’ll give it a shot and post the code when finished. Thanks for the help, the grid is really cool!

    Imported from legacy forums. Posted by Brett (had 450 views)

    Xceed Support
    Member
    Post count: 5658

    I just added an example of how to alternate data-row styles to the documentation. So here you go!

    <code>
    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    xmlns:local=”clr-namespace:Xceed.Wpf.Documentation”>
    <Grid.Resources>
    <local:IndexToOddConverter x:Key=”rowIndexConverter”/>
    <Style TargetType=”{x:Type xcdg:DataRow}”>
    <Style.Triggers>
    <DataTrigger Binding=”{Binding RelativeSource={RelativeSource Self},
    Path=(xcdg:DataGridVirtualizingPanel.ItemIndex),
    Converter={StaticResource rowIndexConverter}}”
    Value=”True”>
    <Setter Property=”Background”>
    <Setter.Value>
    <SolidColorBrush Color=”LightGray”
    Opacity=”0.1″/>
    </Setter.Value>
    </Setter>
    </DataTrigger>
    </Style.Triggers>
    </Style>
    </Grid.Resources>
    <xcdg:DataGridControl x:Name=”OrdersGrid”
    ItemsSource=”{Binding Source={x:Static Application.Current},
    Path=Orders}”>
    </xcdg:DataGridControl>
    </Grid>
    </code>

    C# converter
    <code>
    namespace Xceed.Wpf.Documentation
    {
    public class IndexToOddConverter : System.Windows.Data.IValueConverter
    {
    public object Convert( object value, System.Type targetType, object parameter,
    System.Globalization.CultureInfo culture )
    {
    if( value.GetType() != typeof( int ) )
    {
    throw new System.ArgumentException( “This converter can only converter integer values”,
    “value” );
    }
    int index = ( int )value;
    return ( ( index % 2 ) == 1 );
    }
    public object ConvertBack( object value, System.Type targetType,
    object parameter, System.Globalization.CultureInfo culture )
    {
    throw new System.NotImplementedException();
    }
    }
    }
    </code>

    Imported from legacy forums. Posted by Jenny [Xceed] (had 494 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m actually getting an error in your code…

    Path=(xcdg:DataGridVirtualizingPanel.ItemIndex)

    Error: “Property path is not valid. ‘DataGridVirtualizingPanel’ does not have a public property named ‘ItemIndex’.”

    I’m looking into other places to get the item index as we speak…

    Imported from legacy forums. Posted by Brett (had 687 views)

    Xceed Support
    Member
    Post count: 5658

    Hmmm. I am using the latest version of the source code (which is not publicly available). I should have checked first—the ItemIndex property does not exist in the current public release.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 345 views)

    User (Old forums)
    Member
    Post count: 23064

    Any other suggestions then? I’ve looked for other ways to get the item index, but not seeing anything.

    Imported from legacy forums. Posted by Brett (had 366 views)

    Xceed Support
    Member
    Post count: 5658

    I looked around with some of the developers and there does not seem to be a way to do this (for now). The ItemIndex property will be available in the next release, so hopefully, you can wait till then.

    Marc—he had originally replied to you—created this part of the grid and is much more aware of the possibilities than I am… but he is away for the next week or so.

    Sorry if I got your hopes up, but at least you know it will work in version 1.1!

    Imported from legacy forums. Posted by Jenny [Xceed] (had 6125 views)

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