[英]WPF Prism MEF View lazy loading
I am discovering my views via MEF and Prism. 我通过MEF和Prism发现了自己的观点。 However the constructor imports things which I do not want to load until after the full bootstrap has completed.
但是,构造函数会导入直到完整的引导程序完成后才希望加载的内容。
Rather than MEF go and instantiate all these objects for me at bootstrap time, I just want to register a View with MEF and a particular region, however only to construct and load it when I navigate to it for the first time. 我不是想在引导时为我实例化所有这些对象,而是只想向MEF和特定区域注册一个View,但是只能在我第一次导航到它时构造并加载它。
Is this possible? 这可能吗?
[Export("LegacyEntry")]
[ViewExport]
[PartCreationPolicy(CreationPolicy.Shared)]
public partial class LegacyEntry
{
public IEntryViewModel ViewModel
{
set => DataContext = value;
}
You would need to add Lazy<T>
when importing the module. 导入模块时,您需要添加
Lazy<T>
。 Something like this: 像这样:
[Import]
Lazy<LegacyEntry> LegacyEntry { get; set; }
or multiple 或多个
[ImportMany]
IEnumerable<Lazy<LegacyEntry>> LegacyEnties { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.