Silverlight Prism Cloud Events
In a Silverlight prism app I have a scope (ContentControl) and want to remove the active active view before adding another view. I tried to use the region.PropertyChanged event, but it doesn't fire. I can do this in code where I add a new view, but that will scatter my code. How do you achieve this? Thanks for the answer.
+2
a source to share
1 answer
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 code, you can do: regionManager.RemoveCurrentlyActiveAndThenAdd<MyView)("MyRegion");
+3
a source to share