从外部文件或程序集中加载WPF样式或其他静态资源 [英] Load WPF styles or other Static Resources from an external file or assembly

查看:198
本文介绍了从外部文件或程序集中加载WPF样式或其他静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个WPF应用程序,我希望所有样式都放在一个共享程序集中,而不是在每个应用程序中分别声明它们.

I have a few WPF applications and I want all my styles to be in a shared assembly instead of declaring them in each application separately.

我正在寻找一种方法,因此不必在现有应用程序中更改所有的Style="{StaticResource BlahBlah}".我只想添加对此样式程序集的引用,并将其从当前应用程序中删除,因此它是从程序集中获取的.

I am looking for a way so I don't have to change all my Style="{StaticResource BlahBlah}" in the existing applications; I just want to add the reference to this style assembly, and delete it from the current application, so it's taken from the assembly.

有什么办法吗?

推荐答案

引用外部ResourceDictionary(XAML文件):

Referencing an external ResourceDictionary (XAML File):

<Application.Resources>
    <ResourceDictionary Source="MyResources.xaml" />
</Application.Resources>

引用外部ResourceDictionary(DLL):

Referencing an external ResourceDictionary (DLL):

<Application.Resources>
    <ResourceDictionary Source="/MyExternalAssembly;component/MyResources.xaml" />
</Application.Resources>

这篇关于从外部文件或程序集中加载WPF样式或其他静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆