WPF动态切换语言动态切换字典

<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="1.xmal"></ResourceDictionary>
                <ResourceDictionary Source="2.xmal"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

 

描述
 
 合并多个外部资源字典成为本地字典。当需要合并更多字典的时候只要在ResourceDictionary.MergedDictionaries节中顺序增加引用。
 
特别提示
 
 合并字典(MergedDictionaries 集合中的字典)中对同一对象的同一子元素进行定义的时候,会产生覆盖效果:在这种情况下,所返回的资源将来自在 MergedDictionaries 集合中最后一个找到的字典。(在这里会显示myresourcedictionary2.xaml中的定义)。
 
合并字典(MergedDictionaries 集合中的字典)中对同一对象的不同子元素定义的时候会产生叠加效果。
 
动态换肤,也就是后台更改合并资源
 
合并资源放在APP级:姜彦201808191332
 
Application.Current.Resources.MergedDictionaries.Clear();               
ResourceDictionary newRD = new ResourceDictionary();               
newRD.Source = new Uri("1.xaml", UriKind.Relative);               
Application.Current.Resources.MergedDictionaries.Add(newRD);
 
合并资源放在Window级: 非常有效 姜彦201808191332
 
this.Resources.MergedDictionaries.Clear();               
ResourceDictionary newRD = new ResourceDictionary();               
newRD.Source = new Uri("1.xaml", UriKind.Relative);                       
this.Resources.MergedDictionaries.Add(newRD);
 
如果有多个资源合并在一起,只想更改某个资源,可以这样更改 非常有效 姜彦201808191332
 
ResourceDictionary newRD = new ResourceDictionary();newRD.Source = new Uri("1.xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries[0] = newRD;
自己备注:根据你在App.xaml中的位置,决定数组的index 非常有效 姜彦201808191332
例如:

ResourceDictionary newRD = new ResourceDictionary();
newRD.Source = new Uri("/Utility.Tool.Language;component/Language/en_US.xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries[7] = newRD;

posted @ 2018-08-22 11:44  <--青青子衿-->  阅读(210)  评论(0编辑  收藏  举报
// /**/ // 在页脚Html代码 引入 // function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; $("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);