简体   繁体   English

允许用户自定义主题颜色

[英]Allowing users to customize theme colors

I have a windows 8.1 XAML application. 我有一个Windows 8.1 XAML应用程序。 I want to allow users to customize the theme of the app themselves - for example, I want to give them a color picker where they can set various colors in the app, which would set various resources used across my app. 我想允许用户自己自定义应用程序的主题-例如,我想给他们一个颜色选择器,使他们可以在应用程序中设置各种颜色,从而可以设置应用程序中使用的各种资源。

The issue though, is I cant find out how to dynamically change the value of a resource. 但是,问题是我找不到如何动态更改资源值的方法。 I know in 8.1 they added the concept of a theme resource, which allows me to change from light to dark theme at runtime and what not. 我知道在8.1中,他们添加了主题资源的概念,这使我可以在运行时从浅色主题转换为深色主题,而其他则不能。 But my issue is that I'd like to say 'the backgroundColor resource is now going to be orange, and all items using this resource will reflect this change' 但是我的问题是我想说“ backgroundColor资源现在将变为橙色,并且使用此资源的所有项目都将反映此更改”

I believe the DynamicResource XAML element is what I needed, but that seems to be from WPF and not supported in Win8. 我相信我需要的是DynamicResource XAML元素,但这似乎来自WPF,而Win8不支持。 Does anyone have suggestions? 有人有建议吗?

In short - I want to be able to easily provide dynamic resource brushes. 简而言之-我希望能够轻松提供动态资源画笔。

Unfortunately I do not believe that there is a nice built in way of doing this so any solution is likely to be a little bit hacky or unpleasant. 不幸的是,我不认为这样做有很好的内在方式,因此任何解决方案都可能有点笨拙或令人不快。

This question has some good answers of which this answer is my personal favourite. 这个问题有一些好的答案, 这个答案是我个人最喜欢的。 The downside is that it results in the ViewModel taking on a bit more responsibility for the view than is ideal. 缺点是它导致ViewModel对视图承担的责任比理想情况多。

实际上,您可以根据用户的选择动态访问要更改的元素的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM