zoukankan      html  css  js  c++  java
  • 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};
  • 相关阅读:
    SQLMAP注入教程-11种常见SQLMAP使用方法详解
    VS2012/2013/2015/Visual Studio 2017 关闭单击文件进行预览的功能
    解决 IIS 反向代理ARR URLREWRITE 设置后,不能跨域跳转 return Redirect 问题
    Spring Data JPA one to one 共享主键关联
    JHipster 问题集中
    Spring Data JPA 定义超类
    Spring Data JPA查询关联数据
    maven命名
    maven仓库
    Jackson读取列表
  • 原文地址:https://www.cnblogs.com/m7777/p/6088561.html
Copyright © 2011-2022 走看看