开发者

Silverlight prism region events

开发者 https://www.devze.com 2022-12-27 04:19 出处:网络
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

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");

0

精彩评论

暂无评论...
验证码 换一张
取 消