MEF 组件上的 ShowDialog 只能运行一次
我创建了一个 WPF 窗口并将其设为 MEF 导出。
我可以在 MEF 导入上执行一次 ShowDialog,但第二次它会中止,因为 MEF 组件被第一个 ShowDialog 关闭。
可以做什么来允许重复 ShowDialog?
I created a WPF Window and made it a MEF Export.
I can do a ShowDialog once on the MEF Import but the second time it aborts because the MEF component was closed by the first ShowDialog.
What can be done to allow repeats of ShowDialog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您像这样在 WPF 窗口上调用 ShowDialog 两次时:
您将收到带有以下消息的
InvalidOperationException
:要解决此问题,您需要每次重新创建窗口,例如:
要在 MEF,您可以导出一个单独的控制器组件,该组件负责创建然后显示您的对话框(而不是直接导出对话框):
When you call ShowDialog on a WPF window twice like this:
you will get an
InvalidOperationException
with this message:To fix this, you need to recreate the window each time, e.g. like this:
To do this in MEF, you could export a separate controller component which is responsible for creating and then showing your dialog (rather than exporting your dialog directly):
有关如何在 WPF 应用程序中使用 MEF 的更多示例,请参阅WPF 应用程序框架 (WAF) 项目下载(查看示例应用程序)。
Further examples on how to use MEF within a WPF application can be found in the WPF Application Framework (WAF) project download (have a look at the sample applications).