如果没有 App.xaml,则从不同程序集访问 WPF 资源
我正在为现有 Win32 MFC 客户端应用程序创建 WPF 扩展。在位于我的 WPF 类库中的 UserControl 中,我按如下方式合并库:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyResourceDLL;Component/dictionaries/styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
我也尝试
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyResourceDLL;Component/dictionaries/styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
过在任何一种情况下,我都会收到以下 XamlParseException:
System.Windows.Markup.XamlParseException 发生
消息=“MyResourceDLL;组件/字典/styles.xaml” 无法将值分配给属性 对象的“来源” '系统.Windows.资源字典'。 无法找到资源 'ems.wpf.resources;组件/字典/styles.xaml'。 对象错误 'System.Windows.ResourceDictionary' 中 标记文件 'SARMaster.Maryln.EphemerisLib;组件/getephemeriscontrol.xaml' 第 9 行位置 37。”
我有办法加载主项目未引用的相关 DLL 吗?
I have am creating a WPF extension to an existing Win32 MFC client application. Within a UserControl located in my WPF class library, I am merging libraries as follows:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyResourceDLL;Component/dictionaries/styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
I also tried
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyResourceDLL;Component/dictionaries/styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
In either case, I get the following XamlParseException:
System.Windows.Markup.XamlParseException
occurred
Message="MyResourceDLL;Component/dictionaries/styles.xaml'
value cannot be assigned to property
'Source' of object
'System.Windows.ResourceDictionary'.
Cannot locate resource
'ems.wpf.resources;component/dictionaries/styles.xaml'.
Error at object
'System.Windows.ResourceDictionary' in
markup file
'SARMaster.Maryln.EphemerisLib;component/getephemeriscontrol.xaml'
Line 9 Position 37."
I there a way I can load a relative DLL that is not referenced by main project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近一直在关注同样的问题。编译 Win32 CLR 项目时,不会复制 MFC 项目引用的程序集的依赖项,因此我只需设置一个生成后事件来将适当的程序集复制到 $(TargetDir)。
并不理想,但我相信这是设计使然。
I've been looking at the same issue recently. When compiling a Win32 CLR project the dependencies of the assemblies referenced by the MFC project aren't copied, so I simply set up a post-build event to copy the appropriate assemblies to the $(TargetDir).
Not ideal, but I believe it's by design.
我遇到了同样的问题,并且找到了解决方案。我需要删除 ContentPresenter 的样式。这一行创建了 XamlParseException:
修复此错误后,我需要执行以下步骤才能 100% 正常工作:
这里是我的项目:
Class Library
项目我想用的。它包含我的样式为此:
ResourceDictionary
MainProject 中的 MyStyle.xaml:
I got the same problem and I found the solution. I needed to remove the Style of my ContentPresenter. This line was creating the XamlParseException:
And after fixing this error, I needed to do these steps to have something 100% working:
Here my projects:
Class Library
project that I want to use. It contains my stylesTo do so:
ResourceDictionary
called MyStyle.xaml inside my MainProjectCode: