Created
March 21, 2011 22:29
-
-
Save Jonsey/880369 to your computer and use it in GitHub Desktop.
View Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UIViewService : IUIViewService | |
{ | |
readonly IRegionManager _regionManager; | |
public UIViewService(IRegionManager regionManager) | |
{ | |
_regionManager = regionManager; | |
} | |
public void ActivateNewOrExistingViewInContentItem(UIElement view, string viewName, string regionName) | |
{ | |
var workspaceRegion = _regionManager.Regions[regionName]; | |
var existingView = workspaceRegion.GetView(viewName) as UIElement; | |
if (existingView == null) | |
{ | |
workspaceRegion.Add(view, viewName); | |
workspaceRegion.Activate(view); | |
} | |
else | |
{ | |
workspaceRegion.Activate(existingView); | |
} | |
} | |
public void CloseView(UIElement view, string viewName, string regionName) | |
{ | |
var workspaceRegion = _regionManager.Regions[regionName]; | |
var existingView = workspaceRegion.GetView(viewName) as UIElement; | |
if (existingView == null) | |
{ | |
return; | |
} | |
else | |
{ | |
workspaceRegion.Remove(view); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment