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

Colums Background

5 Answers 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tom Klein
Top achievements
Rank 1
Tom Klein asked on 18 Jan 2010, 01:02 PM
Hey all,

Im trying to give my rows specific colours. I want to do this by binding to a colour, but it's giving me some problems. Here's what I got right now.
 <telerikGrid:RadGridView x:Name="TasksGridView"  
        ItemsSource="{Binding Tasks}"  
        DataContext="{Binding}"  
        AutoGenerateColumns="False"  
        IsReadOnly="True"  
        CanUserFreezeColumns="False" 
        DataLoadMode="Asynchronous" 
        > 
            <telerikGrid:RadGridView.Columns> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Subject}" Header="Subject" Background="{Binding Category.BackColor, Converter={StaticResource colorToSolidColorBrushConverter}}"/> 
 
           </telerikGrid:RadGridView.Columns> 
</telerikGrid:RadGridView> 

And the converter:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            var color = (Color) value; 
 
            return new SolidColorBrush(color); 
        } 

Basically Im converting a colour to a solidcolorbrush, as you can see. However, when I try and run this code I get the following error:
AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 30 Position: 119]
   --- Inner Exception ---
The given key was not present in the dictionary.

Does anyone know what's causing this? The bindings are all correct, they work fine if I use a datatemplate and a stackpanel. But the stackpanel doesn't look as nice as giving the background of the column a colour.
Thanks for taking the time to read about my problem, I hope someone has the solution.









5 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 19 Jan 2010, 12:11 PM
Hi Tom Klein,

The error you are getting occurs because you are trying to set binding to property which is not a FrameworkElement.
The Background property is of type Brush, which does not have Binding property and can be set only from the code behind or set to static resource in Xaml.

Regards,
Tsvyatko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ronald Evers
Top achievements
Rank 1
answered on 28 Jan 2010, 11:20 AM
Would it be possible to bind my background to a brush in another way? Basically each cell of each column has to have a specific colour depending on what colour is defined for the object it's binding to.
0
Tsvyatko
Telerik team
answered on 28 Jan 2010, 12:40 PM
Hi Ronald Evers,

Please check the attached sample - it demonstrates how you can use binding in addition with converter to change cells background depending on the current data item. It also demonstrates how to change cell foreground in the same way.

I hope this helps.

Best wishes,
Tsvyatko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Carlos
Top achievements
Rank 2
answered on 26 Jul 2011, 02:44 PM
You said:

"The error you are getting occurs because you are trying to set binding to property which is not a FrameworkElement.
The Background property is of type Brush, which does not have Binding property and can be set only from the code behind or set to static resource in Xaml."

Your example uses the "can be set only from the code behind " aproach, but I needed the static resource one.. can you help me here?

Thanks in advance,
Carlos
0
Tsvyatko
Telerik team
answered on 26 Jul 2011, 04:59 PM
Hello Carlos,

 Since my last last response, we have made many improvements in this area and currently I can suggest to look in our CellStyleSelectors that can help in your scenario:
http://www.telerik.com/help/silverlight/gridview-cell-style-selector.html
http://demos.telerik.com/silverlight/#GridView/Selectors/StyleSelectors/CellStyleSelector
http://demos.telerik.com/silverlight/#GridView/Selectors/DataTemplateSelectors/DeclarativeDefinition

Kind regards,
Tsvyatko
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Tom Klein
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Ronald Evers
Top achievements
Rank 1
Carlos
Top achievements
Rank 2
Share this question
or