Click here to Skip to main content
11,933,253 members (63,024 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET WPF .NET4 event
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 6-Sep-12 7:36am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^],[^],[^],[^].

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:[^].

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100