MEF - 从其他视图显示视图

发布于 2024-09-28 10:26:32 字数 638 浏览 7 评论 0原文

我正在学习 MEF,但在理解它时遇到一些问题。我有一个带有 MainWindow 的小项目和一些加载到目录中的程序集。 如果我单击该按钮,其中一个程序集需要在开始时和稍后显示其他程序集的视图。 这是该视图的头部:

[Export("OperatingPlugin", typeof(UserControl))]    
[ExportMetadata("Name", "EDIFACT Viewer")]
[ExportMetadata("Dock", "main")]
[ExportMetadata("Hidden",true)]
[ExportMetadata("Icon","editedi.xaml")]
public partial class EdiView : UserControl
{
    //[Import("PluginSelectFile", typeof(UserControl))]
    //public Lazy<UserControl> SelectFile { get; set; }

加载视图时,我想显示另一个选择文件的视图(在单独的程序集中)。 我可以在 app.xaml.cs 的目录中看到所有视图(还有 PluginSelectFile),但是在删除上述注释后,该程序集(EDIFACT 查看器)不再显示。 我哪里缺少什么?

I'm learning MEF and have some problems with understanding it. I have small project with MainWindow and some assemblies which are loaded into catalog.
One of the assemblies need to show a view from other assembly, once at a start and later, if I click the button.
Here is the head part of this view:

[Export("OperatingPlugin", typeof(UserControl))]    
[ExportMetadata("Name", "EDIFACT Viewer")]
[ExportMetadata("Dock", "main")]
[ExportMetadata("Hidden",true)]
[ExportMetadata("Icon","editedi.xaml")]
public partial class EdiView : UserControl
{
    //[Import("PluginSelectFile", typeof(UserControl))]
    //public Lazy<UserControl> SelectFile { get; set; }

When the view loads, I want to show another view (in separate assembly) which selects a file.
I can see in catalog in app.xaml.cs all views (also PluginSelectFile), but after the comments above are removed this assembly (EDIFACT Viewer) is no more showing.
Where I am something missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许你一世情深 2024-10-05 10:26:32

当取消注释时,PluginSelectFile 的导出很可能与导入不匹配,或者存在多个匹配的导出,这两种情况都会导致 OperatingPlugin 导出被拒绝。

请参阅我的博客文章 如何调试和诊断 MEF 故障,详细了解发生这种情况的原因以及如何解决该问题。

Most likely the export of PluginSelectFile doesn't match the import when uncommented, or there are multiple matching exports, both of which would cause the OperatingPlugin export to be rejected.

See my blog post on How to Debug and Diagnose MEF Failures for details on why this happens and how you can figure out how to fix it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文