Clearing the Views from the Particular view

Topics: Prism v4 - WPF 4
Nov 18, 2011 at 12:16 PM

Hi All,

I want to clear the Views from particular region. I have used the following code but i couldn't solution on views clearing.

 

   foreach ( var view in regionManager.Regions[RegionNames.MainViewRegion].Views)
            {
                while (view != null)
                {
                    regionManager.Regions[RegionNames.MainViewRegion].Remove(view);
                }
                

            }

Please find the solution for removing the views from the particular region.

 

Thanks and regards,

Sakthi

Developer
Nov 18, 2011 at 4:30 PM

Sakthi,

You could try something like this:

var regionManager = ServiceLocator.Current.GetInstance<IRegionManager(); 
var myRegion = regionManager.Regions["MainRegion"];

            while (myRegion.Views.Count() > 0)
            {
                myRegion.Remove(myRegion.Views.First());
            }

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi