/// <summary> /// Shows the document in the main shell. /// </summary> /// <typeparam name="TViewModel">The type of the view model.</typeparam> /// <param name="viewModel">The view model to show which will automatically be resolved to a view.</param> /// <param name="tag">The tag.</param> /// <param name="dockingSettings">The docking settings.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception> public void ShowContextSensitiveDocument <TViewModel>(TViewModel viewModel, object tag = null, DockingSettings dockingSettings = null) where TViewModel : IViewModel { Argument.IsNotNull("viewModel", viewModel); Log.Debug("Showing document for view model '{0}'", viewModel.UniqueIdentifier); var viewType = GetViewType(viewModel); var document = AvalonDockHelper.FindDocument(viewType, tag); if (document == null) { var view = ViewHelper.ConstructViewWithViewModel(viewType, viewModel); document = AvalonDockHelper.CreateDocument(view, tag); if (dockingSettings != null) { AvalonDockHelper.AddNewDocumentToDockingManager(dockingSettings, document); } } AvalonDockHelper.ActivateDocument(document); Log.Debug("Showed document for view model '{0}'", viewModel.UniqueIdentifier); }
/// <summary> /// Shows the helper window. /// </summary> /// <typeparam name="TViewModel">The type of the view model.</typeparam> /// <param name="tag">The tag.</param> public void ShowDocumentIfHidden <TViewModel>(object tag = null) where TViewModel : IViewModel { var viewLocator = GetService <IViewLocator>(); var viewType = viewLocator.ResolveView(typeof(TViewModel)); var document = AvalonDockHelper.FindDocument(viewType, tag); if (document != null) { document.Show(); Log.Debug("Show hidden document '{0}'", document.Title); } Log.Debug("Can not show hidden view because it can not be found for viewmodel type {0}", typeof(TViewModel)); }
/// <summary> /// Closes the document in the main shell with the specified view model. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="tag">The tag.</param> public void CloseDocument(IViewModel viewModel, object tag = null) { Argument.IsNotNull(() => viewModel); Log.Debug("Closing document for view model '{0}'", viewModel.UniqueIdentifier); var viewType = GetViewType(viewModel); var document = AvalonDockHelper.FindDocument(viewType, tag); if (document == null) { Log.Warning("Cannot find document belonging to view model '{0}' with id '{1}' thus cannot close the document", ObjectToStringHelper.ToTypeString(viewModel), viewModel.UniqueIdentifier); } else { AvalonDockHelper.CloseDocument(document); } Log.Debug("Closed document for view model '{0}'", viewModel.UniqueIdentifier); }
/// <summary> /// Shows the document in the main shell. /// </summary> /// <typeparam name="TViewModel">The type of the view model.</typeparam> /// <param name="viewModel">The view model to show which will automatically be resolved to a view.</param> /// <param name="tag">The tag.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception> public void ShowDocument <TViewModel>(TViewModel viewModel, object tag = null) where TViewModel : IViewModel { Argument.IsNotNull("viewModel", viewModel); Log.Debug("Showing document for view model '{0}'", viewModel.UniqueIdentifier); var viewLocator = GetService <IViewLocator>(); var viewType = viewLocator.ResolveView(viewModel.GetType()); var document = AvalonDockHelper.FindDocument(viewType, tag); if (document == null) { var view = ViewHelper.ConstructViewWithViewModel(viewType, viewModel); document = AvalonDockHelper.CreateDocument(view, tag); } AvalonDockHelper.ActivateDocument(document); Log.Debug("Showed document for view model '{0}'", viewModel.UniqueIdentifier); }