Silverlight prism region events
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 fo开发者_高级运维r reply.
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");
精彩评论