This question is locked. New answers and comments are not allowed.
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.
Here is the XAML for the custom RowStyleSelector in the control that has that RadGridView:
Here's the code for the custom RowStyleSelector class:
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
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