I have a DataGrid control in my WPF application that contains an object. There is a logical property of this object that can be changed by user actions. I need the line style to change when the property value changes.
I wrote a class that descends from StyleSelector :
public class LiveModeSelector : StyleSelector { public Style LiveModeStyle { get; set; } public Style NormalStyle { get; set; } public override Style SelectStyle( object item, DependencyObject container ) { DataGridRow gridRow = container as DataGridRow; LPRCamera camera = item as LPRCamera; if ( camera != null && camera.IsInLiveMode ) { return LiveModeStyle; } return NormalStyle; } }
The presented View Model class implements INotifyPropertyChanged , and it raises the PropertyChanged event when the corresponding property changes.
// Note: The ModuleMonitor class implements INotifyPropertyChanged and raises the PropertyChanged // event in the SetAndNotify generic method. public class LPRCamera : ModuleMonitor, ICloneable { . . . public bool IsInLiveMode { get { return iIsInLiveMode; } private set { SetAndNotify( "IsInLiveMode", ref iIsInLiveMode, value ); } } private bool iIsInLiveMode; . . . /// </summary> public void StartLiveMode() { IsInLiveMode = true; . . . } public void StopLiveMode() { IsInLiveMode = false; . . . } }
The value of the property changes when the user performs the required action, but the style does not change.
I set a breakpoint in the SelectStyle method, and I see that the breakpoint is hit when the control first loads, but it doesn't hit when the property value changes.
What am I missing?
source share