Coloring grid rows based on data values

3 posts, 0 answers
  1. David
    David avatar
    7 posts
    Member since:
    Oct 2010

    Posted 01 Oct 2010 Link to this post

    Hello,

    I tried using this approach that I found in the WPF forums: http://www.telerik.com/community/forums/wpf/gridview/setting-radgridview-row-background-color-based-on-the-value-of-a-column-in-the-row.aspx

    However, this isn't working for me in Silverlight. I get the following error:
    "XamlParseException occurred."
    Set property '' threw an exception. [Line: 41 Position: 69]

    Here is my Xaml:

     

     

     

    <telerik:RadGridView x:Name ="itemGrid" IsReadOnly="False"

     

     

     

    AutoGenerateColumns="False"

     

     

     

    ItemsSource="{Binding AdTypes, Mode=TwoWay}"

     

     

     

    SelectedItem="{Binding SelectedItem, Mode=TwoWay}"

     

     

     

    IsSynchronizedWithCurrentItem="False"

     

     

     

    RowIndicatorVisibility="Collapsed"

     

     

     

    >

     

     

     

     

    <telerik:RadGridView.RowStyle>

     

     

     

     

    <Style TargetType="telerik:GridViewRow">

     

     

     

     

    <Setter Property="Background" Value="{Binding Active, Converter={StaticResource ActiveConverter} }"></Setter>

     

     

     

     

    </Style>

     

     

     

     

    </telerik:RadGridView.RowStyle>
    ...
    </telerik:RadGridView>

     

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 07 Oct 2010 Link to this post

    Hi David,

    Unfortunately Silverlight does not support binding such binding in style setters but you can apply the same binding in code-behind using our RowLoaded event. For example:

    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = (from c in Enumerable.Range(0, 10)
                            select new Order
                            {
                                Due_Date = DateTime.Now.AddDays(c),
                                ID = c,
                                Name = "Name" + c
                            }).ToList();
      
        this.gridView.RowLoaded += new EventHandler<RowLoadedEventArgs>(gridView_RowLoaded);
    }
      
    void gridView_RowLoaded(object sender, RowLoadedEventArgs e)
    {
        var row = e.Row as GridViewRow;
      
        if (row != null)
        {
            Binding b = new Binding("Due_Date");
            b.Source = e.Row.Item;
            b.Converter = new DateToColorConveter();
      
            row.SetBinding(GridViewRow.BackgroundProperty, b);
        }
    }


    All the best,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Joseph Gershgorin
    Joseph Gershgorin avatar
    28 posts
    Member since:
    Aug 2009
Back to Top