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

查看:29
本文介绍了从外部文件或程序集加载 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天全站免登陆