1

I have a corner case where both dynamic resources (don't allow for converters) and custom markup extensions (only evaluated once) won't do the trick. I want to create gradient brushes based on faded variants of the current system colors. Those brushes should update themselves whenever the system's color theme changes, so that users don't need to restart the application in case they switch to an accessibility theme.

Is it possible to detect changes of the system's color theme at runtime within an WPF application? Some kind of event?

3 Answers3

1

According to this answer you should be able to use Windows Messages to change your brushes when the windows theme changes.

Community
  • 1
  • 1
Eirik
  • 4,135
  • 27
  • 29
1

You might want to check out the Microsoft.Win32.SystemEvents class.

hbarck
  • 2,934
  • 13
  • 16
0

I stumbled across this answer whilst trying to detect the changes in Visual Studio 2012's themes. I was writing an Add-In that used WPF user controls and needed to know when it was in Dark versus Light theme. The system event that I used thanks to hbarck above was:

Microsoft.Win32.SystemEvents.UserPreferenceChanged += (s, e) => { DoSomething(); };

This event is triggered when the user clicks OK on changing the VS theme in tools->options.

The Senator
  • 5,181
  • 2
  • 34
  • 49