当从外部 xap 加载并且程序集由 MEF 提供时,如何获取 ResourceDictionary 样式?
我有以下设置:
主应用程序加载带有 IPlugin 实现的 XAP。该插件包含一个“DisplayPanel”,其中包含引用的控件和其他控件。这里的 DisplayPanel 只是一个容器控件,用于显示引用的 Control。
此引用的控件来自程序集,使用此程序集中的 ResourceDictionary xaml 中的样式。至少那是我想要拥有的。问题是引用的 Control 抛出错误:
无法找到具有名称/键 PlayerPanelGrad 的资源 [行:1500 位置:127]
我尝试通过合并资源字典引用来引用 theResourceDictionary 来获取样式:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TableControls;component/ControlsStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
但这不起作用。
你会如何处理这个问题?
I've got the following setup:
The main application loads a XAP with an IPlugin implementation. The Plugin contains a 'DisplayPanel' that contains a referenced Control with other controls. The DisplayPanel here is simply a container control to show referenced Control.
This referenced Control, from an assembly, uses a Style from a ResourceDictionary xaml in this assembly. At least that's what I want to have. The problem is that the referenced Control throws an error:
Cannot find a Resource with the Name/Key PlayerPanelGrad [Line: 1500
Position: 127]
I've tried to get at the style by referencing theResourceDictionary through a Merged Resource dictionary reference:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TableControls;component/ControlsStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
But that doesn't work.
How would you approch this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我让它工作的唯一方法是在 InitializeComponent 调用之前以编程方式将资源字典加载到控件(在类库中):
the only way i got it to work is by loading the Resource dictionary into the control (in a Class Library) programmatically before the InitializeComponent call:
这个问题可能会有所帮助,但老实说,我仍在尝试自己解决这个问题:
使用 MEF 导入 WPF 数据模板?
This question may be of help, although, honestly, I'm still trying to figure it out myself:
Using MEF to import a WPF DataTemplate?
//先动态加载other.dll,然后使用以下代码:
//load other.dll dynamically first,and then use the following code:
为了将来参考,我的 XAML 文件位于需要
/
字符的解决方案的子目录中,但该文件还位于其中名为Assets
的子目录中。此外,.XAML 文件在解决方案中构建为
Page
。For future reference, my XAML file was found in a subdirectory of the solution which needed the
/
character but also file was further in a subdirectory namedAssets
within it.Also the .XAML file was built as
Page
in the solution.