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. JavaScript - 正则表达之二

    正则表达式的大致匹配过程是:依次拿出表达式和文本中的字符比较,如果每一个字符都能匹配,则匹配成功:一旦有匹配不成功的字符则匹配失败. 正则表达式通常用于在文本中查找匹配的字符串.Python里数量词默 ...

  2. eclipse安装spring的插件

    第一步:插件下载 http://spring.io/tools/sts/all 安装包链接 第二步:插件安装 第三步:安装成功检测

  3. 在sql语句中使用 xml for path 格式化字符串的方法总结

    此方法实现的是将查询表中的某个字段,格式化成  字符串1,字符串2,字符串3...的格式 假设我们现在有两个表 分别是 分组表 grouped和分组成员表 groupuser grouped表有连个字 ...

  4. Android中处理崩溃异常

    转自:http://my.eoe.cn/817027/archive/17997.html 大家都知道,现在安装Android系统的手机版本和设备千差万别,在模拟器上运行良好的程序安装到某款手机上说不 ...

  5. redis实战(01)_redis安装

    早就想对redis进行实战操作了,最近看了一些视频和参考书籍,总结总结一下,redis实战内容: 实战前先对redis做一个大概的认识: 现在开始安装redis了... redis的安装下载地址 ht ...

  6. kernel 4.4.12 EETI eGTouch 电容屏驱动移植

    kernel 4.4.12 EETI eGTouch 电容屏驱动移植: 在make menuconfig 里面添加如下选项: 添加通过事件上报接口节点: Device Drivers ---> ...

  7. 【项目】百度搜索广告CTR预估

    -------倒叙查看本文. 6,用auc对测试的结果进行评估: auc代码如下: #!/usr/bin/env python import sys def auc(labels,predicted_ ...

  8. Linux远程复制命令SCP

    scp test.json savo@yourdomain.com:/usr/share/nginx/test # 以上命令需配置好ssh

  9. 那些PHP中没有全称的简写

    PHP中的GD库,全网没发现GD二字母的全称是什么,包括PHP.net,都搜不到GD.G应该是graphi,D是什么? die: 从php_mysql.dll到php_mysqli的变化,那个i是什么 ...

  10. js_继承

    一,js中对象继承 js中有三种继承方式 1.js原型(prototype)实现继承 复制代码代码如下: <SPAN style="<SPAN style="FONT- ...