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中方式的更多相关文章

  1. WPF之资源字典zz

    最近在看wpf相关东西,虽然有过两年的wpf方面的开发经验,但是当时开发的时候,许多东西一知半解,至今都是模模糊糊,框架基本是别人搭建,自己也就照着模板写写,现在许多东西慢慢的理解了,回顾以前的若干记 ...

  2. WPF 为资源字典 添加事件响应的后台类

    原文:WPF 为资源字典 添加事件响应的后台类 前言,有许多同学在写WPF程序时在资源字典里加入了其它控件,但又想写事件来控制这个控件,但是资源字典没有CS文件,不像窗体XAML还有一个后台的CS文件 ...

  3. WPF合并资源字典

    1.合并多个外部资源字典成为本地字典 示例代码 <Page.Resources> <ResourceDictionary> <ResourceDictionary.Mer ...

  4. WPF使用资源字典组织资源

    转载:http://blog.163.com/wangzhenguo2005@126/blog/static/371405262010111413321728/     首先在解决方案资源管理器中添加 ...

  5. WPF 遍历资源字典中的控件

    object obItem=this.FindResource("canvasdt"); if (obItem is System.Windows.DataTemplate) { ...

  6. WPF(MVVM) 利用资源字典实现中英文动态切换

    1.首先新建两个字典文件en-us.xaml.zh-cn.xaml.定义中英文的字符串在这里面. 2.将两个资源字典添加到App.xaml中,这里注意下,因为两个字典中有同样字符,如果没有动态更改,默 ...

  7. WPF 界面实现多语言支持 中英文切换 动态加载资源字典

    1.使用资源字典,首先新建两个字典文件en-us.xaml.zh-cn.xaml.定义中英文的字符串在这里面[注意:添加xmlns:s="clr-namespace:System;assem ...

  8. WPF中关于合并资源字典

    一.本项目中 <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <!--<ResourceD ...

  9. wpf多程序集之间共享资源字典--CLR名称空间未定义云云

    wpf多程序集之间共享资源字典--CLR名称空间未定义云云 分类: WPF 2012-10-28 10:57 1162人阅读 评论(0) 收藏 举报 以下介绍如何创建可用于在多个程序集之间共享的资源字 ...

随机推荐

  1. 记录下WIN下配置LINUX虚拟机及PYTHON环境

    因为听说服务器端大多都是LINUX/UNIX,LINUX是程序员必须适应的编程环境,所以今天折腾了一下,给笔记本装了个LINUX虚拟机,并顺便给WINDOWS和LINUX都配置了PYTHON环境. 这 ...

  2. Linq练习

    首先在Program.cs的Main()方法下添加如下代码: string[] names = { "heh", "haha", "huahua&qu ...

  3. 【bzoj2073】[POI2004]PRZ

    题目描述 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时只能分批 ...

  4. pip安装报错:is not a supported wheel on this platform

    可能的原因1:安装的不是对应python版本的库,下载的库名中cp27代表python2.7,其它同理. 可能的原因2:这个是我遇到的情况(下载的是对应版本的库,然后仍然提示不支持当前平台) 我下载到 ...

  5. 面向过程(POP)、面向对象(OOP)、面向接口(IOP)、面向切面(AOP)

    面向过程:典型的是C/C++的结构体,结构体里只有变量,没有处理变量的方法,需要专门编写处理变量的方法. 面向对象:ArrayList<Integer> list=new ArrayLis ...

  6. git 发布命令

    git add . git commit -m "备注" git push -u origin master

  7. java面试题总汇

    coreJava部分 7 1.面向对象的特征有哪些方面? 7 2.作用域public,private,protected,以及不写时的区别? 7 3.String 是最基本的数据类型吗? 7 4.fl ...

  8. [转]VS2012 快捷键

    Ctrl+E,D ----格式化全部代码       Ctrl+A+K+F Ctrl+E,F ----格式化选中的代码     Ctrl+K+F CTRL + SHIFT + B生成解决方案   Al ...

  9. java中scanner类的用法

    在Eclipse中编写程序时,如果我们的变量是需要手动输入的时候,我们就可以用到scanner类了. Scanner类,这是一个用于扫描输入文本的新的实用程序.由于任何数据都必须通过同一模式的捕获组检 ...

  10. tableview最后一行显示不全

    最后一行显示不全是因为表格的高度大于了控制view的高度,减小表格的高度小于的等于控制的view的高度即可