Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to launch an event whenever the user switches to/from High Contrast Mode in Windows.

I'm currently able to accomplish this by using the SystemEvents.UserPreferenceChanged event. This however fires multiple times and is not just for high contrast. I noticed that .Net 4.5 actually has a SystemParameters.StaticPropertyChanged event but I'm using 4.0 and won't be going to 4.5 anytime soon.

I'm still learning WPF and C# for the most part and was wondering if there's a good clean way to do this?
Posted

1 solution

The problem has nothing to do with WPF itself. I think you still need to handle SystemEvents.UserPreferenceChanging and SystemEvents.UserPreferenceChanged events and ignore the events not related to high contrast. This is the very usual practice. The class Microsoft.Win32.SystemEvents does not provide any filters for the event, but you can filter out the event by the value of the Category property of the event arguments:
http://msdn.microsoft.com/en-us/library/microsoft.win32.userpreferencechangingeventargs.category.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.userpreferencechangedeventargs.category.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.userpreferencechangedeventargs.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.userpreferencechangingeventargs.aspx[^].

Most likely, the only category you need in this case is Microsoft.Win32.UserPreferenceCategory.Accessibility, but you can also handle the cases with Microsoft.Win32.UserPreferenceCategory.Color:
http://msdn.microsoft.com/en-us/library/microsoft.win32.userpreferencecategory.aspx[^].

—SA
 
Share this answer
 
v3
Comments
Member 9346729 11-Sep-12 9:42am    
Forgot to respond. Worked perfectly. I was able to filter it for the accessibility changes and now it only goes through my function once when a change is made which is what I was looking for. Thank you.
Sergey Alexandrovich Kryukov 11-Sep-12 13:12pm    
It's a pleasure to help when an inquirer can really use it and do the job properly.
You are very welcome.
Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900