Removing view from Region

Topics: Prism v4 - Silverlight 4
Jul 26, 2012 at 11:59 AM

Hi to all friends out there.

I have view in my region defined in shell.My view load perfectly fine and i need to change view on user action in that Region.

When i am tring to remove it by using remove method of regionManager it is giving error

"The region does not contain the specified view.
Parameter name: view"

I added my view in this view to shell in this way.

_region.RegisterViewWithRegion("RegionA", typeof(ChartAView));

I am able to remove view by using IViewsCollection like this way:

  IViewsCollection regionlist= _region.Regions["RegionA"].Views;

            foreach (var item in regionlist)
           // }

By this view gets remove.

So my question is that by this method it remove all views in this region.How i can remove particular View in that REGION and why it give error when i use remove method mentioned above.

Thanks in advance.



Jul 26, 2012 at 2:33 PM
Edited Jul 26, 2012 at 2:34 PM


Take into account that when using the View Discovery approach to add views to a region like shown above, you do not have explicit control over these views. For cases when you need a programmatic control or you need to remove a specific view from a region like you mentioned, View Injection is the recommended approach.

You can find more information about this in the following chapter of the Prism documentation:

For example, as mentioned in this chapter when using this approach you could add a view with a specific view name like this:

IRegion region = regionManager.Regions["RegionA"];

var myChartAView= container.Resolve<ChartAView>();

region.Add(myChartAView, "myChartAViewName");

And once you added the view using a specific viewName, you can retrieve it from the region and remove it like this:

var myView = region.GetView("myChartAViewName");


I hope you find this helpful,

Agustin Adami