如何显示满足所有导入的用户控件
我在使用 Silverlight 4/MEF 时遇到一些问题。我有一个以 Silverlight 导航应用程序为核心的基本框架设置。
图像链接到图表以进行说明
主应用程序 (Desu) 包含一些页面并很好地控制导出和导入。我动态加载来自 Desu.Controls 的控件(例如我使用 IImageViewer 界面识别的图像查看器)和来自 Desu.Pages 的一些页面。
我遇到的第一个问题是动态加载页面并能够导航到这些页面(例如,当从 xap 加载 Desu.Pages 时使用 dummyhttp://blagh/desutestpage.aspx#/Activation)。我通过使用自定义 MetaAttribute 和自定义内容加载器解决了这个问题。
现在进入问题部分: 我想从Desu主页的Desu.Controls加载ImageViewerControl。我还没有将 Desu.Controls 加载到包中。当我尝试加载控件时,它给了我 CompositionException 因为它无法满足 ImageViewControl 导入。我尝试设置AllowRecomposition = true但这没有帮助。
那么是否可以在不满足所有导入的情况下加载控件?如果可以,如何做到这一点?
I'm having some issues with Silverlight 4/ MEF. I have a basic framework setup with a Silverlight Navigation app at the core.
Image link to the diagram for clarification
The main app (Desu) contains some pages and controls that export en import nicely. I dynamicly load controls from Desu.Controls(like an imageviewer which i identify with the IImageViewer interface) and some pages from Desu.Pages.
The first problem I had was with dynamicly loading pages and being able to navigate to these pages (eg. use dummyhttp://blagh/desutestpage.aspx#/Activation when Desu.Pages was loaded from the xap). I solved this by using a custom MetaAttribute and a custom contentloader.
Now for the question part:
I want to load the ImageViewerControl from Desu.Controls in HomePage in Desu. I haven't loaded the Desu.Controls into the package though. When i try to load the control it gives me CompositionException because it can't satisfy the ImageViewControl import. I tried setting AllowRecomposition=true but that didn't help.
So is it possible to load a control without satisfying all imports and, if yes, how does one do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么您希望导入最初不被满足,但您希望稍后添加它?
设置AllowRecomposition=true 是正确的,但您还需要设置AllowDefault=true。如果 ImageViewerControl 不可用,则该属性将为 null,并在可用时设置。
So you want the import to initially not be satisfied, but you want it to be added later?
You were on the right track with setting AllowRecomposition=true, but you also need to set AllowDefault=true. Then the property will be null if the ImageViewerControl isn't available, and will be set when it becomes available.