如何在WPF的Xaml中检测当前主题?
我有一个自定义控件,在带有 Aero 主题的 XP 或 Vista 上运行时需要进行微调,是否有一种简单的方法来检测主题(操作系统检测不够,因为用户可以更改主题)并在风格触发器?
我需要在 Vista 上应用一个小的边距更改以获得所需的外观:
<Setter Property="Margin"
Value="0,-1,0,-1" />
上面的设置器当前是无条件的(例如不在触发器中),但需要我有两个版本。
理想情况下,解决方案应该只是 Xaml,但如果有必要,我可以公开一个属性来关联到 DataTrigger。
I have a custom control that needs a minor adjustment when running on XP or Vista with the Aero theme, is there a simple way to detect the theme (operating system detection isn't enough because the user can change the theme) and use this in a style trigger?
I need to apply a small margin change on Vista to get the look required:
<Setter Property="Margin"
Value="0,-1,0,-1" />
The above setter is currently unconditional (e.g. not in a Trigger) but requires me having two versions.
Ideally the solution should be Xaml only, but if necessary I could expose a property to associate to a DataTrigger
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个 ValueConverter 来获取边距设置并在其 Convert 方法中进行平台/主题检查。
You could write a ValueConverter that takes the margin settings and does a platform/theme check in its Convert method.