Strange problem with RowStyleSelector

3 posts, 0 answers
  1. Nick
    Nick avatar
    3 posts
    Member since:
    Jan 2011

    Posted 29 Mar 2012 Link to this post

    I'm developing a WPF application that allows the user to switch the color scheme by pressing a button.  It does this by defining identically named SolidColorBrush resources in two different ResourceDictionaries that are stored in the program's Resources.  When the user clicks on the button, one ResourceDictionary is swapped out for the other in the Application object's MergedDictionaries property.  This is working very well, but I've been having issues getting the Telerik controls to play along with the changes.

    I have a RadGridView control on my program's Search screen.  It contains objects called "Reads" that are retrieved from a database that match criteria the user specifies in other controls on the Search screen.  A Read can have 0 or more "Alarms" associated with it.  The Read object contains a boolean property called HasAlarms that is set to true if the number of Alarms associated with the Read is greater than 0.

    I wrote a custom RowStyleSelector class to change the foreground color of the row if the HasAlarms property is true.  This has worked well in the past.  However, lately, I've found that the foreground color isn't changing.  Just to make sure everything was still working, I added a Setter to the HasAlarms style to change the FontWeight property too.  I see the FontWeight change on those rows that have alarms, but the foreground color still isn't changing.

    The program has alternated back and forth between the color change working and not working all week.  I've been working on making the whole color change scheme work at the same time.  That is, I've been modifying the Background and Foreground another other properties of various controls to use the named resources defined in the ResourceDictionaries.  The color changed worked as recently as yesterday afternoon.  I left work and went home, then came back today and now it's not working again.

    Here is a style that is in my app.xaml.  It is used to style the DataGridCells in all of the RadGridView controls in my application, except for the one that uses the custom RowStyleSelector.

    <Style TargetType="{x:Type telerik:GridViewCell}">
        <Setter Property="Background" Value="{DynamicResource DataBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource DataForeground}" />

    Here is the XAML for the custom RowStyleSelector in the control that has that RadGridView:

    <cs:AlarmsRowStyleSelector x:Key="StyleSelector">
            <Style TargetType="telerik:GridViewRow">
                <Setter Property="Background" Value="{DynamicResource TextBackground}" />
                <Setter Property="Foreground" Value="Red" />
                <Setter Property="FontWeight" Value="Bold" />
            <Style TargetType="telerik:GridViewRow">
                <Setter Property="Background" Value="{DynamicResource TextBackground}" />
                <Setter Property="Foreground" Value="{DynamicResource TextForeground}" />

    Here's the code for the custom RowStyleSelector class:

    public class AlarmsRowStyleSelector : StyleSelector {
        public Style HasAlarmsStyle { get; set; }
        public Style NoAlarmsStyle { get; set; }
        public override Style SelectStyle( object item, DependencyObject container ) {
            ReadViewModel row = item as ReadViewModel;
            if ( row != null && row.HasAlarms ) {
                // It does.  Return the HasAlarmsStyle.
                return HasAlarmsStyle;
            return NoAlarmsStyle;

    I have tried running my program with the GridViewCell Style as shown, without it in the code at all, and even as a resource attached to the particular control in which it was needed.  There is no difference in the behavior.  Right now, I keep seeing rows with alarms that aren't red.  The Bold FontWeight setting is definitely seen, but the row has to be red and it is not.

    What's wrong with my program?

  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 30 Mar 2012 Link to this post


     This is indeed a strange behaviour. Would you please confirm the exact version of the RadControls that you use? 

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Tony
    Tony avatar
    111 posts
    Member since:
    May 2011

    Posted 30 Mar 2012 Link to this post


    I'm the original poster.  I had logged in using my manager's ID so I could download the latest version of the Telerik UI Components library and I forgot to logout and back in as me.

    I'm using the latest build.  I just downloaded it yesterday.  It's version 2012.1.326.40.

    Also, I'm using the WPF library, not Silverlight.  I don't know how this got posted in the Silverlight forum.

Back to Top