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

Strange problem with RowStyleSelector

2 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 29 Mar 2012, 08:42 PM
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}" />
</Style>

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

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

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?

Tony

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Mar 2012, 03:33 PM
Hello,

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

Regards,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Tony
Top achievements
Rank 1
answered on 30 Mar 2012, 03:59 PM
Didie:

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.

Tony
Tags
GridView
Asked by
Nick
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Tony
Top achievements
Rank 1
Share this question
or