跨项目/dll 访问 Xaml 中的资源 [英] Accessing resources in Xaml across projects/dlls
本文介绍了跨项目/dll 访问 Xaml 中的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从另一个项目引用存储在 ResourceDictionary(构建操作 = 资源)中的 Xaml 资产?我想将资产合并到主项目的资源字典中或单独访问它们.例如:
Is it possible to reference Xaml assets stored in a ResourceDictionary (build action = resource) from another project? I would like to either merge the assets into the main project's resource dictionary or access them individual. For example:
- 项目MyResources"包含一个名为Assets"的文件夹,其中包含一个名为MyAssets.xaml"的ResourceDictionary,其中包含一个名为ButtonStyle"的样式
- 项目MainProject"引用了 MyResources;在 MainWindow.xaml 中
在 MainWindow.xaml 中,我想执行以下操作:
In MainWindow.xaml I'd like to do something like:
<ResourceDictionary.MergedResources>
<ResourceDictionary Source="/MyResources/Assets/MyAssets.xaml"/>
</ResourceDictionary.MergedResources>
或者,如果这是不可能的,也许:
Or, if that's not possible, perhaps:
<Button Style="{StaticResource /MyResources/Assets/MyAssets.xaml}"/>
有没有办法从 MainProject 中引用 MyResources 中的内容?
Is there a way to refer to stuff in MyResources from MainProject?
推荐答案
<ResourceDictionary.MergedResources>
<ResourceDictionary Source="pack://application:,,,/YourAssembly;component/Subfolder/YourResourceFile.xaml"/>
</ResourceDictionary.MergedResources>
这篇关于跨项目/dll 访问 Xaml 中的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文