wpf 切换资源字典的2中方式
var _1200RDUri = new Uri(String.Format(@"/aa;Component/Themes/1200Theme.xaml"), UriKind.RelativeOrAbsolute);
var _980RDUri = new Uri(String.Format(@"/aa;Component/Themes/980Theme.xaml"), UriKind.RelativeOrAbsolute);
var _1200RD = Application.LoadComponent(_1200RDUri) as ResourceDictionary;
var _980RD = Application.LoadComponent(_980RDUri) as ResourceDictionary;
if (_1200RD == null || _980RD == null)
{
return;
}
if (!IsScreenWidthAbove1200)
{
Application.Current.Resources.MergedDictionaries.Remove(_1200RD);
Application.Current.Resources.MergedDictionaries.Remove(_980RD);
Application.Current.Resources.MergedDictionaries.Add(_980RD);
}
else
{
Application.Current.Resources.MergedDictionaries.Remove(_1200RD);
Application.Current.Resources.MergedDictionaries.Remove(_980RD);
Application.Current.Resources.MergedDictionaries.Add(_1200RD);
}
private static void ChangeAppStyle(ResourceDictionary resources, Tuple<AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme)
{
var themeChanged = false;
if (oldThemeInfo != null)
{
var oldAccent = oldThemeInfo.Item2;
if (oldAccent != null && oldAccent.Name != newAccent.Name)
{
var key = oldAccent.Resources.Source.ToString().ToLower();
var oldAccentResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key);
if (oldAccentResource != null)
{
resources.MergedDictionaries.Add(newAccent.Resources);
resources.MergedDictionaries.Remove(oldAccentResource); themeChanged = true;
}
} var oldTheme = oldThemeInfo.Item1;
if (oldTheme != null && oldTheme != newTheme)
{
var key = oldTheme.Resources.Source.ToString().ToLower();
var oldThemeResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key);
if (oldThemeResource != null)
{
resources.MergedDictionaries.Add(newTheme.Resources);
resources.MergedDictionaries.Remove(oldThemeResource); themeChanged = true;
}
}
}
else
{
ChangeAppStyle(resources, newAccent, newTheme); themeChanged = true;
} if (themeChanged)
{
OnThemeChanged(newAccent, newTheme);
}
}
这段不能直接用,得看一下代码意思 Application.Current.Resources
Resources = new ResourceDictionary {Source = resourceAddress};
wpf 切换资源字典的2中方式的更多相关文章
- WPF之资源字典zz
最近在看wpf相关东西,虽然有过两年的wpf方面的开发经验,但是当时开发的时候,许多东西一知半解,至今都是模模糊糊,框架基本是别人搭建,自己也就照着模板写写,现在许多东西慢慢的理解了,回顾以前的若干记 ...
- WPF 为资源字典 添加事件响应的后台类
原文:WPF 为资源字典 添加事件响应的后台类 前言,有许多同学在写WPF程序时在资源字典里加入了其它控件,但又想写事件来控制这个控件,但是资源字典没有CS文件,不像窗体XAML还有一个后台的CS文件 ...
- WPF合并资源字典
1.合并多个外部资源字典成为本地字典 示例代码 <Page.Resources> <ResourceDictionary> <ResourceDictionary.Mer ...
- WPF使用资源字典组织资源
转载:http://blog.163.com/wangzhenguo2005@126/blog/static/371405262010111413321728/ 首先在解决方案资源管理器中添加 ...
- WPF 遍历资源字典中的控件
object obItem=this.FindResource("canvasdt"); if (obItem is System.Windows.DataTemplate) { ...
- WPF(MVVM) 利用资源字典实现中英文动态切换
1.首先新建两个字典文件en-us.xaml.zh-cn.xaml.定义中英文的字符串在这里面. 2.将两个资源字典添加到App.xaml中,这里注意下,因为两个字典中有同样字符,如果没有动态更改,默 ...
- WPF 界面实现多语言支持 中英文切换 动态加载资源字典
1.使用资源字典,首先新建两个字典文件en-us.xaml.zh-cn.xaml.定义中英文的字符串在这里面[注意:添加xmlns:s="clr-namespace:System;assem ...
- WPF中关于合并资源字典
一.本项目中 <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <!--<ResourceD ...
- wpf多程序集之间共享资源字典--CLR名称空间未定义云云
wpf多程序集之间共享资源字典--CLR名称空间未定义云云 分类: WPF 2012-10-28 10:57 1162人阅读 评论(0) 收藏 举报 以下介绍如何创建可用于在多个程序集之间共享的资源字 ...
随机推荐
- Codility NumberSolitaire Solution
1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...
- java基础 绘图技术.坦克大战 之java绘图坐标体系(一)
坐标体系介绍 下图说明了java坐标体系.坐标原点位于左上角,以像素为单位,像素是计算机屏幕上最小的显示单位.在java的坐标系中,第一个是x坐标,表示当前位置为水平方向,距离坐标原点x个像素:第二个 ...
- PHP之compact()函数
PHP之compact()函数 compact()函数将变量转化为数组: <?php //直接调用函数 $a=1;$b=3;$c=4; var_dump($a,$b,$c); //自定义函数实现 ...
- jquery复选框 选中事件 及其判断是否被选中
jquery复选框 选中事件 及其判断是否被选中 (2014-07-25 14:03:54) 转载▼ 标签: jquery复选框选中事件 分类: extjs jquery 今天做了 显示和不显示密 ...
- Android 常用开发工具以及Mac常用软件
Android 常用的开发工具记录.其中包括AndroidStudio(IDEA)插件.Mac 上好用的软件以及国内知名Android开发者博客等. Android Studio 插件 codota ...
- 安装windows下的Cscope
http://blog.csdn.net/maxiee/article/details/10034263 Cscope 是一款用于查看大型工程中的代码的软件.它使用方便,支持快速查找 C Symbol ...
- LRU LFU FIFO 转载
-------------------------------------->href--------------------------> http://blog.chinaunix.n ...
- python界面
import easygui as g import sys while 1: g.msgbox("我一定要学会编程!","加油!") #choices = [ ...
- 【EasyUI】 日期格式化
本文经过了测试,解决getFullyear() is not a function等问题 效果如下: 首先: Oracle中字段设置为DATE,MySQL中设置为DATETIME,MyBatis中会自 ...
- InstallSheild的一些常量
在用InstallShield制作安装包的时候,我们经常需要用到一些常量,弄清楚这些常量的具体含义,可以方便我们灵活使用脚本. TARGETDIR 默认安装路径,在安装过程中用户可手动更改.如:安装 ...