.net 重写WPF中的静态资源

.net 重写WPF中的静态资源,.net,wpf,xaml,resources,staticresource,.net,Wpf,Xaml,Resources,Staticresource,我想重写在我自己的资源字典中的不同程序集的资源字典中配置的StaticResource。我尝试使用相同的密钥配置新资源,但没有成功。实际加载的资源来自上述程序集的资源字典 出于演示目的,我将该资源称为“MyResource”: MyResourceDictionary.xaml: <ResourceDictionary xmlns=...> <!-- I use the same key as the original resource, from the other

我想重写在我自己的资源字典中的不同程序集的资源字典中配置的
StaticResource
。我尝试使用相同的密钥配置新资源,但没有成功。实际加载的资源来自上述程序集的资源字典

出于演示目的,我将该资源称为“MyResource”:

MyResourceDictionary.xaml:

<ResourceDictionary xmlns=...>
    <!-- I use the same key as the original resource, from the other assembly -->
    <DataTemplate x:Key="MyResource">
        <!--My own implementation of that resource -->
    </DataTemplate>
</ResourceDictionary>

App.xaml

<Application x:Class=...>
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!-- Resource dictionary from different assembly -->
                <ResourceDictionary Source="pack://application:,,,/Assembly;component/ResourceDictionary.xaml"/>
                <!-- My resource dictionary -->
                <ResourceDictionary Source="pack://application:,,,/MyApplication;component/ResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

请注意,WPF的行为与您描述的不一样,这可能是重复的-正如您在上面的回答中所看到的,它会查找从上次添加到首次添加的词典。所以你肯定还遗漏了什么。可能使用了错误的名称?