相关疑难解决方法(0)

将合并字典添加到合并字典

我似乎无法将合并的字典添加到XAML中的合并字典集合中.

Theme.xaml

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Mine;component/Themes/Palette.Blue.xaml"/>
    <ResourceDictionary Source="/Mine;component/Themes/Template.xaml"/>
</ResourceDictionary.MergedDictionaries>
Run Code Online (Sandbox Code Playgroud)

应用资源

<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>
Run Code Online (Sandbox Code Playgroud)

注意:如果我将两个ResourceDictionaries放在Appication.Resources MergedDictionary中(注释掉theme.xaml并取消注释其他两个词典),它们都会正确加载.但是,我们的资源定义方式,这可能意味着将加载相当多的资源,而对于动态加载,我希望能够定义模板.

silverlight wpf xaml resourcedictionary

21
推荐指数
1
解决办法
1万
查看次数

合并字典中共享的静态资源

我目前正在研究可以动态应用于我的应用程序的样式和模板字典.在这个"新想要的"动态行为之前,我有几个资源字典,每个样式控件一个,我在App.xaml中合并:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="ColorsDictionary.xaml"/>
            <ResourceDictionary Source="ControlsTemplatesDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

现在,我希望我的应用程序被设置样式,所以我决定将我以前的所有资源合并到一个名为"MyFirstTemplates"的新资源中,并且只将这个字典添加到App.xaml中.

新词典"MyFirstTemplates.xaml":

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">"
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="ColorsDictionary.xaml"/>
        <ResourceDictionary Source="ControlsTemplatesDictionary.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

新的App.xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="MyFirstTemplates.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <Style TargetType="{x:Type Window}"/>
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

注意:Window的默认样式是更正WPF 4的错误,请参阅将合并字典添加到合并字典

现在我已经做了这个改变,我不能再使用"ColorsDictionary.xaml"中的颜色资源作为"ControlsTemplateDictionary.xaml"中的StaticResource了.如果我改回到在app.xaml中合并这些文件,一切正常.为了使它工作,我必须为DynamicResource更改这些StaticResource.你知道为什么这不再起作用吗?

谢谢 :-)

wpf merge dictionary staticresource

9
推荐指数
1
解决办法
4162
查看次数