0

In .NET 4.5, I can use:

        SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged;

but this is not supported in .NET 4.0. However, SystemParameters does give access to the HighContrast value and HighContrastKey ResourceKey. How can I monitor the value of the ResourceKey for changes so that I can mimic the PropertyChanged event? I know that a DynamicResource in XAML can do this, but this needs to be done in code behind.

Is it possible to detect changes in a ResourceKey value using just C# and not XAML?

Update The reason I cannot use .NET 4.5 is that (1) XP is not supported, and (2) my installer insists that he needs to detect and install 4.5.2 (not 4.5 or 4.51) which means all OSs must install .NET. Ugh.

NextInLine
  • 2,126
  • 14
  • 23
tofutim
  • 22,664
  • 20
  • 87
  • 148
  • 3
    Not exactly monitoring the ResourceKey, but when a User Setting is changed a [SystemEvents.UserPreferenceChanged](https://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.userpreferencechanged(v=vs.100).aspx) event will be fired. If the user changes to a High Contrast mode the UserPreferenceChangedEventArgs's Category will be Accessibility. – Szabolcs Dézsi Mar 04 '15 at 20:58
  • Your answer Szabolcs is best – tofutim Mar 06 '15 at 21:14

2 Answers2

0

You may be able to use WMI to monitor for registry key changes using the code here. You would just have to figure out what keys correspond to the themeing values. You could use the registry key change as a signal to examine the properties you are looking for.

Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76
0

I would recommend taking advantage of the fact that it is a DynamicResource in WPF and act accordingly. Basically,

  1. Create a DependencyProperty with a changed handler
  2. Bind that property to the HighContrastKey (if doing this from code, see How to assign a dynamic resource style in code?)

Then, when it changes, you can trigger whatever action is necessary.

Community
  • 1
  • 1
NextInLine
  • 2,126
  • 14
  • 23