PRISM 4 - RegisterViewWithRegion & Custom Export Attributes
I am using Prism 4 with MEF Extensions and the MVVM pattern. During initialization in a module I call RegisterViewWithRegion(RegionNames.MyRegion, typeof(MyView)) which works perfectly when the view is constructed like this:
The view gets registered and everything is fine. As soon as I change the Export to a Custom Export Attribute the view can't be found anymore, although it is still in the container. This Custom Export Attribute is taken from the Stock Trader RI:
and the interface is
By changing the Export Attribute to
when calling RegisterViewWithRegion it throws an error: Activation error occured while trying to get instance of type MyView, key "" Any advice? I was looking at this part of code the whole day without finding a solution. |
|||||
|
Another day, another way... I will try to answer my question even though I have only limited knowledge about PRISM. In other words: I'm still learning. The Custom Export Attribute taken from the Stock Trade RI is used by the
But I think when using ViewInjection and Prism Navigation it is better to just use the default [Export] attribute, then everything works smoothly. |
|||
Are you configuring the aggregate catalog in your MEF bootstrapper? If so, are you adding the assembly that contains your ViewExportAttribute and AutoPopulateExportedViewsBehavior classes? I believe this happens in the StockTraderRI's bootstrapper with this line:
The StockTraderRICommands class is in the same assembly as the ViewExportAttribute and AutoPopulateExportedViewsBehavior classes. |
|||||
|
The custom export attribute passes As far as the activation error you'll need to look at the exception in more detail. The root cause is probably there somewhere, perhaps buried under an InnerException. |
|||
I encountered exactly the same problem and it was a hard one for a MEF/PRISM beginner. okieh describes the problem very well, I just want to post an alternative solution, coming from theStocktraderUI sample application: The solution works (/seems to work) if you want View discovery without any form of config file, etc. where you have to register your views. 1. Modify the
The [Export] attribute is added and the base constructor is now called with 2. Modify
The That's basically it. You can use the This way, you don't need additional interfaces for your views and can still discover everything without hardcoded registration. I hope it helps and let me know, if I missed any drawbacks of my solution. http://stackoverflow.com/questions/6271167/prism-4-registerviewwithregion-custom-export-attributes |
最新文章
- matlab 有趣小细节
- 重走java--Step 2
- Win7 64位 VS2013环境cuda_7.5.18的一些坑
- ThinkPHP中getField( )和field( )
- hdu5390 tree
- RM报表 刷新打印机列表
- (一)学习C#之浮点类型float小结
- 取得root权限后怎么删除程序
- Linux文件误删除恢复操作
- The CircuitCalculator.com Blog a blog with live web calculators Home About Policies Contact PCB
- VelocityTracker简单介绍
- HDU 2203 亲串(kmp)
- python进阶之time模块详解
- tree与GridView交互
- QML C++插件dll引用
- alibaba的FastJson(高性能JSON开发包) json转换
- Java 中 synchronized的用法详解(四种用法)
- Splay-Tree理解
- 深入理解Object提供的阻塞和唤醒API
- 单机ZooKeeper配置