theme.xaml
<ResourceDictionary.MergedDictionarIEs> <ResourceDictionary Source="/mine;component/themes/Palette.Blue.xaml"/> <ResourceDictionary Source="/mine;component/themes/Template.xaml"/></ResourceDictionary.MergedDictionarIEs>
应用资源
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionarIEs> <ResourceDictionary Source="/mine;component/themes/theme.xaml"/> <!-- <ResourceDictionary Source=="/mine;component/themes/Palette.Blue.xaml"/> <ResourceDictionary Source="/mine;component/themes/Template.xaml"/> --> </ResourceDictionary.MergedDictionarIEs> </ResourceDictionary></Application.Resources>
注意:如果我将两个ResourceDictionarIEs都放在Appication.Resources MergedDictionary中(注释掉了theme.xaml并取消了其他两个字典的注释),他们都正确地加载。然而,我们的资源定义的方式,这可能意味着将加载相当多的资源,对于动态加载,我想能够定义模板。
解决方法 这是一个优化错误,请参阅 this链接On the creation of every object in
XAML,if a default style is present
(i.e. style w/ a key of Type) that
style should be applIEd. As you can
imagine there are several performance
optimizations to make that (implIEd)
lookup a light weight as possible. One
of them is that we don’t look insIDe
Resource DictionarIEs unless they are
flagged as “containing default
Styles”. There is a BUG: if all your
default styles are nested in merged
dictionarIEs three levels deep (or
deeper) the top dictionary does not
get flagged so the search skips it.
The work around is to put a default
Style to something,anything,in the root
Dictionary.
所以添加一个虚拟样式到根字典修复这个。例
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionarIEs> <ResourceDictionary Source="/mine;component/themes/theme.xaml"/> </ResourceDictionary.MergedDictionarIEs> <!-- Dummy Style,anything you won't use goes --> <Style targettype="{x:Type Rectangle}" /> </ResourceDictionary></Application.Resources>总结
以上是内存溢出为你收集整理的wpf – 将合并的词典添加到合并词典中全部内容,希望文章能够帮你解决wpf – 将合并的词典添加到合并词典中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)