In silverlight prism application I have a region (ContentControl) and would like to remove currently active view before adding another view. I tried to use region.PropertyChanged event but it doesn't fire. I can do it in the code where I add new view, but that will scatter my code. How to achieve this? Thanks for reply.
+2
A:
public static class RegionManagerExtensions
{
public static void RemoveCurrentlyActiveAndThenAdd<TView>(
this IRegionManager regionManager,
string regionName)
{
var region = regionManager.Regions[regionName];
while (region.ActiveViews.Any())
region.Remove(region.ActiveViews.First());
var view = ServiceLocator.Current.GetInstance(typeof(TView));
regionManager.Regions[regionName].Add(view);
}
}
Then in your code you can do: regionManager.RemoveCurrentlyActiveAndThenAdd<MyView)("MyRegion");
PL
2010-04-13 03:10:52
I accept this answer but still would like to know why propertychanged wouldn't fire
synergetic
2010-04-13 07:08:03