开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜