wpf - 从外部项目引用资源字典
问题描述
是否可以在单独的库(框架)项目中制作资源字典,然后在另一个库项目中引用它?在这个单独的项目中,我有一个想要使用它的 UserControl。
这就是我的解决方案的设置方式。
SharedProject 有资源字典,我在我的插件项目中引用它。然后我将我的插件库导出到 MainProject 并让它显示我的插件视图。
我有所有这些工作......除了我的字典。我尝试在每个视图中引用我的字典
<UserControl.Resources>
<ResourceDictionary x:Key="dictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/InternalShared;component/Resources/Dictionary1.xaml"/>
<ResourceDictionary Source="pack://application:,,,/InternalShared;component/Resources/Dictionary2.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
但是当我尝试引用现有样式时...
<Button Command="{Binding CommandOpenFile}"
Style="{DynamicResource GenericButtonStyle}"
IsEnabled="{Binding IsEnabled}"
Content="Restore Window"
Height="Auto" />
但我得到资源“GenericButtonStyle”无法解决。这种情况在我尝试引用任何字典中的样式的任何地方都会发生。我不知道为什么。
谁能告诉我为什么会这样?我还需要在其他地方设置此声明吗?
解决方案
我维护一个由许多不同解决方案使用的外部 WPF UI 库。
- 确保 InternalShared 是 WPF DLL
- 将您的外部资源合并到
App.xaml
您的主 WPF 应用程序中
例如,使用我的资源的应用程序将它们合并为这样:
<ResourceDictionary Source="/InternalShared;component/Resources/Dictionary1.xaml"/>
推荐阅读
- r - R Shiny styleColorBar 应用于列的子集
- c++ - 在基类中创建派生内部类的实例
- c# - Rx.Net + Reactive-Ui + MahApps.Metro - 使用门控对话框重复和重试异步请求
- java - java: 整数太大
- flutter - 使用会员详细信息自动更新颤振应用程序
- php - Wordpress:处理 Paypal 付款并返回页面
- c# - Xml 命名空间前缀规范器
- c - 单链表中没有给我数据的第一个节点有什么问题
- python - Discord.py 创建一个新的频道和脱模版的角色
- node.js - 寻找与时区和日期一起使用的模式前端(React)和后端(nodejs)