• WPF 动态更换样式文件


      ApplySkinFromMenuItem("Style/BigImgStyle.xaml", "Style/FileListStyle.xaml");

      //换肤
            void ApplySkinFromMenuItem(string source, string oldSources)
            {
                string skinDictPath = source;
                App app = Application.Current as App;
                app.ApplySkin(skinDictPath, oldSources);
            }

    ApplySkin(这个方法是写在Application文件中的)

       /// <summary>
            /// 换样式 (这个方法是写在Application文件中的)
            /// </summary>
            /// <param name="newPaths">要加入的新样式文件路径</param>
            /// <param name="oldxamls">要删除的老的样式文件路径</param>
            public void ApplySkin(string newPaths, string oldxamls)
            {
                Collection<ResourceDictionary> mergedDicts = base.Resources.MergedDictionaries;
                string[] ss = oldxamls.Split(',');
                if (ss.Length > 0)
                {
                    foreach (var path in ss)
                    {
                        if (mergedDicts.Count > 0 && path.Trim() != "")
                        {
                            foreach (var item in mergedDicts)
                            {
                                if (item.Source.OriginalString.Trim().EndsWith(path.Trim()))
                                {
                                    mergedDicts.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                }
                if (newPaths != "")
                {
                    try
                    {
                        string[] newss = newPaths.Split(',');
                        if (newss.Length > 0)
                        {
                            foreach (var item in newss)
                            {
                                Uri skinDictionaryUri = new Uri(item, UriKind.Relative);
                                ResourceDictionary skinDict = new ResourceDictionary();
                                //ResourceDictionary skinDict = Application.LoadComponent(skinDictionaryUri) as ResourceDictionary;
                                skinDict.Source = skinDictionaryUri;

                                mergedDicts.Add(skinDict);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("dsds:" + ex.Message);
                    }

                }


            }

  • 相关阅读:
    附加目录中所有的数据库文件
    SQL Server 2008中的GROUPING SETS的应用实例
    Gmail式的上传
    ubuntu9.10下配置需要用户名及密码的上网代理(squid)
    【jQuery】仿IPhone的滑动操作效果
    Ubuntu9.10下Nginx+PHP(Fastcgi) 安装过程
    如何从SQL Server 中取得字段说明
    SQL server 2005 更改数据库名称
    ASP通过SMTP发邮件
    数据库镜像出现“无法访问或不存在"故障的原因和解决方案
  • 原文地址:https://www.cnblogs.com/zhaolili/p/5133996.html
Copyright © 2020-2023  润新知