WPF 4:MergedDictionaries似乎不再起作用了

时间:2010-04-19 20:06:08

标签: wpf styles resourcedictionary

我有以下的XAML块

'BaseStyles.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="ShinyBlue.xaml"/>
        <ResourceDictionary Source="DataGrid.Generic.xaml"/>
    </ResourceDictionary.MergedDictionaries>

</ResourceDictionary>

在设计时引用此工作的表单,但不在运行时引用。 如果我的表单直接引用了ShinyBlue.xaml或DataGrid.Generic.xaml,则该样式表可以正常工作。

修改

如果我将其直接粘贴到表单中,它可以正常工作。显然问题与我的包装器有某种关系。

<Window.Resources>
    <ResourceDictionary Source="../BaseStyles.xaml"/>
</Window.Resources>

作品

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ShinyBlue.xaml"/>
    <ResourceDictionary Source="DataGrid.Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>

1 个答案:

答案 0 :(得分:2)

尝试包括从命名空间到文件名的整个路径:

<ResourceDictionary Source="pack://application:,,,/[YourDll];component/[YourLocation]/ShinyBlue.xaml"/>

其中[YourDll]是项目的名称,[YourLocation]是ResourceDictionary在您的dll中所在的位置。