This is a migrated thread and some comments may be shown as answers.

Coloring grid rows based on data values

2 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 01 Oct 2010, 05:58 PM
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 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 07 Oct 2010, 08:27 AM
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
0
Joseph Gershgorin
Top achievements
Rank 1
answered on 13 Oct 2010, 11:07 PM
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Milan
Telerik team
Joseph Gershgorin
Top achievements
Rank 1
Share this question
or