Background colors of cells missed

2 posts, 1 answers
  1. Fernando
    Fernando avatar
    5 posts
    Member since:
    May 2014

    Posted 01 Oct 2014 Link to this post

    Hello,

    I have a simple application containing a RadGridView with the ItemsSource binded to an ObservableCollection of elements. I use the RowLoaded event to set the background of the cells and it works fine.
    Here is the code i use in the RowLoaded:
                string colorStr = "#5cfc56";
                SolidColorBrush b = new SolidColorBrush();
                b.Color = (Color)ColorConverter.ConvertFromString(colorStr);
                var cell= (from a in e.Row.Cells where a.Column.UniqueName == "a" select a).FirstOrDefault();
                cell.Background = b;
                cell.ToolTip = "aaaas";

    The problem is that when i refresh the ObservableCollection with new elements the grid does not apply the background color to the rows in spite of launching the RowLoadedEvent however the Tooltip of the cell works.

    Is there something i'm doing wrong here?


    Tanks.







  2. Answer
    Yoan
    Admin
    Yoan avatar
    1213 posts

    Posted 01 Oct 2014 Link to this post

    Hello,

    This is the expected behaviour when GridView's Virtualization is enabled. When the virtualization of RadGridView is turned on, its elements are created when they should be brought into view and they are also reused on scrolling (i.e. the rows/cells are recreated on scrolling). Thus, it is not recommended to work with the visual elements (i.e. GridViewRow/GridViewCell) and their properties. You can take a look at the UI Virtualization help article for a reference. The better approach is to work with the data items. Please check the RowStyleSelector and CellStyleSelector help articles for a reference.

    Regards,
    Yoan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top