Skip to content

Instantly share code, notes, and snippets.

@Jonsey
Created March 21, 2011 22:29
Show Gist options
  • Save Jonsey/880369 to your computer and use it in GitHub Desktop.
Save Jonsey/880369 to your computer and use it in GitHub Desktop.
View Service
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