在运行时更改主题 [英] Change theme at runtime

查看:42
本文介绍了在运行时更改主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有主题 (ShinyRed.xaml) 的 WPF 应用程序,我想要一个按钮,单击该按钮时会将主题更改为 ShinyBlue.xaml

I have a WPF application with a theme (ShinyRed.xaml) and I want to have a button that when clicked changes the theme to ShinyBlue.xaml

我最初在 App.xaml 中加载主题:

I load in the theme initially in App.xaml:

<Application.Resources>
    <ResourceDictionary Source="/Themes/ShinyBlue.xaml"/>
</Application.Resources>

我该怎么做?

推荐答案

这里有一篇文章将引导您完成:

Here is an article that will walk you through it:

http://svetoslavsavov.blogspot.com/2009/07/switching-wpf-interface-themes-at.html

基本上,您需要从资源字典中删除旧"主题,然后合并到新主题中.上面的文章向您展示了如何让这个改变变得非常简单.

Basically you need to remove the "old" theme from the resource dictionary and then merge in the new one. The above article shows you how to make this change very simple.

这篇关于在运行时更改主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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