Colums Background

6 posts, 0 answers
  1. Tom Klein
    Tom Klein avatar
    2 posts
    Member since:
    Aug 2009

    Posted 18 Jan 2010 Link to this post

    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.









  2. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 19 Jan 2010 Link to this post

    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.
  3. DevCraft banner
  4. Ronald Evers
    Ronald Evers avatar
    26 posts
    Member since:
    Dec 2009

    Posted 28 Jan 2010 Link to this post

    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.
  5. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 28 Jan 2010 Link to this post

    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.
  6. Carlos
    Carlos avatar
    50 posts
    Member since:
    Feb 2011

    Posted 26 Jul 2011 Link to this post

    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
  7. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 26 Jul 2011 Link to this post

    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!

Back to Top
DevCraft banner