WPF / XAML在App.xaml中使用ResourceDictionary时出错

时间:2016-03-07 01:17:34

标签: wpf xaml resourcedictionary

我在引用xaml资源字典文件时遇到问题,导致在引用内部的ResourceDictionary时出现运行时错误“资源x无法找到”。但是使用Window.Resources节点可以工作。

工作代码:

<Window.Resources>
    <ResourceDictionary Source="Resources\Template_1.xaml">
    </ResourceDictionary>
</Window.Resources>

我的错误代码:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources\Template_1.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

我的问题是我需要应用程序范围内的字典。 我将其作为StaticResource访问,并将Template_1的构建操作设置为“页面”

有什么建议吗?

修改: 这是Template_1.xaml的结构

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:self="clr-namespace:Application_1"
                >
<ControlTemplate x:Key="dict_TabContent" x:Shared="true" >
    <DockPanel>
        ...
    </DockPanel>
</ControlTemplate>
</ResourceDictionary>

0 个答案:

没有答案
相关问题