惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
D
Docker
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
月光博客
月光博客
小众软件
小众软件
量子位
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
博客园 - 叶小钗
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
C
Check Point Blog

博客园 - oldkingsir

angularjs2 学习笔记(六) Form angularjs2 学习笔记(五) http服务 angularjs2 学习笔记(三) 服务 angularjs2 学习笔记(四) 路由 angularjs2 学习笔记(二) 组件 angularjs2 学习笔记(一) 开发环境搭建 Silverlight中利用MEF进行模块注入时注入错误问题分析 prism中ImportingConstructor构造注入时的参数匹配 解决Prism的EventAggregator的事件订阅错误 解决Prism中Region的GetView不起作用问题 想找一个专业一点的silverlight开发的群,谁知道啊! 在Prism中利用Region的对ContentControl的自动充填问题 silverlight 学习笔记 (九):Prism与MVVM模式在silverlight中的应用 由csdn搬家来此 silverlight 学习笔记 (八):Prism中MEF的初步认识 silverlight 学习笔记 (七):Prism的第一个应用 vs2010中使用odac for .net的连接配置 Silverlight中对WCF RIA 的异步调用的同步处理解决办法 silverlight 学习笔记导航
Prism中在Region中注入匹配问题
oldkingsir · 2012-02-25 · via 博客园 - oldkingsir

简单实例说明

View Code

 1 [Export]
 2     public partial class TitleView : UserControl
 3     {
 4         public TitleView()
 5         {
 6             InitializeComponent();
 7         }
 8         [Import("TitleViewModel")]
 9         public TitleViewModel ViewModel { get { return this.DataContext as TitleViewModel; } set { this.DataContext = value; } }
10     }

如果在module中采用如下方式调用 var titleview = ServiceLocator.Current.GetInstance<TitleView>(); 不会有错误.

而如果把上面的[Export]改为[Export("TitleView")] 则会引发异常

Activation error occured while trying to get instance of type TitleView, key ""

解决办法是将调用的方法更改为

var titleview = ServiceLocator.Current.GetInstance(typeof(TitleView), "TitleView");

同样我们在使用RegisterViewWithRegion注册View时如果也发生类似错误也可用此法解决,对应调用方法如下:

this.regionManager.RegisterViewWithRegion(RegionNames.MainTitleRegion, () => { return ServiceLocator.Current.GetInstance(typeof(TitleView), "TitleView"); });