SystemParameter高对比度事件 [英] SystemParameters High Contrast Event

查看:263
本文介绍了SystemParameter高对比度事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户在Windows中切换为高对比度模式时,我都会尝试启动事件.

我目前能够通过使用SystemEvents.UserPreferenceChanged事件来完成此操作.但是,这会触发多次,而不仅仅是为了获得高对比度.我注意到.Net 4.5实际上有一个SystemParameters.StaticPropertyChanged事件,但是我正在使用4.0,并且不会很快到4.5.

我仍在学习WPF和C#的大部分内容,并且想知道是否有一种很好的清洁方法来做到这一点?

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?

推荐答案

问题无济于事使用WPF本身.我认为您仍然需要处理SystemEvents.UserPreferenceChangingSystemEvents.UserPreferenceChanged事件,并忽略与高对比度无关的事件.这是很平常的做法.类Microsoft.Win32.SystemEvents没有为事件提供任何过滤器,但是您可以通过事件参数的Category属性值来过滤事件:
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 [^ ].

在这种情况下,您唯一需要的类别很可能是Microsoft.Win32.UserPreferenceCategory.Accessibility,但是您也可以使用Microsoft.Win32.UserPreferenceCategory.Color处理这种情况:
http://msdn.microsoft.com/en-us/library/microsoft.win32. userpreferencecategory.aspx [ ^ ].

—SA
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


这篇关于SystemParameter高对比度事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆