Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF Events .NET4
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 6:36am

1 solution

Rate this: bad
good
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:
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
  Permalink  
v3
Comments
Member 9346729 at 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 at 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)

  Print Answers RSS
0 CPallini 385
1 BillWoodruff 344
2 George Jonsson 295
3 Sergey Alexandrovich Kryukov 293
4 OriginalGriff 222
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2014
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