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并取消了其他两个字典的注释),他们都正确地加载。然而,我们的资源定义的方式,这可能意味着将加载相当多的资源,对于动态加载,我想能够定义模板。
解决方法
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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。