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

推荐订阅源

Y
Y Combinator Blog
GbyAI
GbyAI
爱范儿
爱范儿
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
M
MIT News - Artificial intelligence
量子位
宝玉的分享
宝玉的分享
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
罗磊的独立博客
F
Fortinet All Blogs
美团技术团队
博客园_首页
博客园 - 【当耐特】
L
LangChain Blog
月光博客
月光博客
腾讯CDC
The Cloudflare Blog
D
Docker
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - oldkingsir

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

通常情况下在Region中添加View时我们需要先判断View是否在Region中已存在,但如果我们在Region.Add的方法调用不当时,我们在GetView中始终返回Null,原因自然是Add时出现了错误

错误回顾

view = ServiceLocator.Current.GetInstance(typeof(ApplicationView), "ApplicationView");

this.RegionManager.Regions[RegionNames.MainContentRegion].Add(view);

通过这种方式我们 在

var view=this.RegionManager.Regions[RegionNames.MainContentRegion].GetView("ApplicationView");

返回结果将始终为Null,下面演示正确的调用方法

var view=this.RegionManager.Regions[RegionNames.MainContentRegion].GetView("ApplicationView");
            if (view == null)
            {
                view = ServiceLocator.Current.GetInstance(typeof(ApplicationView), "ApplicationView");
                this.RegionManager.Regions[RegionNames.MainContentRegion].Add(view, "ApplicationView");
            }
            this.RegionManager.Regions[RegionNames.MainContentRegion].Activate(view);