在运行时更改主题
我使用 JetPack 主题并从 App.xaml 中设置它:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles/Brushes.xaml"/>
<ResourceDictionary Source="Assets/Styles/Fonts.xaml"/>
<ResourceDictionary Source="Assets/Styles/CoreStyles.xaml"/>
<ResourceDictionary Source="Assets/Styles/Styles.xaml"/>
<ResourceDictionary Source="Assets/Styles/SdkStyles.xaml"/>
<ResourceDictionary Source="Assets/Styles/ToolkitStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
如何从代码隐藏中设置主题并在运行时更改主题?
I use JetPack
theme and set it from App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles/Brushes.xaml"/>
<ResourceDictionary Source="Assets/Styles/Fonts.xaml"/>
<ResourceDictionary Source="Assets/Styles/CoreStyles.xaml"/>
<ResourceDictionary Source="Assets/Styles/Styles.xaml"/>
<ResourceDictionary Source="Assets/Styles/SdkStyles.xaml"/>
<ResourceDictionary Source="Assets/Styles/ToolkitStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
How can i set theme from code-behind and change theme at run time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Silverlight Toolkit 基本
Theme
控件提供对在运行时更改主题的支持。不幸的是,像 JetPack 主题这样的应用程序主题不是 Toolkit 主题(询问 Microsoft 为什么)。所以你必须自己转换它们。查看 Toolkit 主题源有助于我们弄清楚如何实现:现在,假设您的资源位于名为 JetPackTheme 的文件夹中,这里是 JetPackTheme.xaml:
现在您应该能够在应用程序中使用 JetPackTheme 控件:
要在运行时更改主题,您只需执行以下操作
The Silverlight Toolkit base
Theme
control provides support for changing a theme at runtime. Unfortunately, the Application Themes like the JetPack Theme are no Toolkit themes (ask Microsoft why). So you'd have to convert them yourself. A look at the Toolkit themes sources helps us to figure out how:Now, assuming your resources are in a folder called JetPackTheme, here is JetPackTheme.xaml:
Now you should be able to use a JetPackTheme control in your application:
To change the theme at runtime, you can simply do