/// <summary> /// Locates the view model, locates the associate view, binds them and shows it as the root view. /// </summary> /// <param name="viewModelType">The view model type.</param> protected async Task DisplayRootViewForAsync(Type viewModelType) { var viewModel = IoC.GetInstance(viewModelType, null); var view = ViewLocator.LocateForModel(viewModel, null, null); if (!(view is Page page)) { throw new NotSupportedException(String.Format("{0} does not inherit from {1}.", view.GetType(), typeof(Page))); } ViewModelBinder.Bind(viewModel, view, null); if (viewModel is IActivate activator) { await activator.ActivateAsync(); } MainPage = page; }
/// <summary> /// Locates the view model, locates the associate view, binds them and shows it as the root view. /// </summary> /// <param name="viewModelType">The view model type.</param> protected void DisplayRootViewFor(Type viewModelType) { var viewModel = IoC.GetInstance(viewModelType, null); var view = ViewLocator.LocateForModel(viewModel, null, null); var page = view as Page; if (page == null) { throw new NotSupportedException(String.Format("{0} does not inherit from {1}.", view.GetType(), typeof(Page))); } ViewModelBinder.Bind(viewModel, view, null); var activator = viewModel as IActivate; if (activator != null) { activator.Activate(); } MainPage = page; }
/// <summary> /// Shows a popup at the current mouse position. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The view context.</param> /// <param name="settings">The optional popup settings.</param> public virtual async Task ShowPopupAsync(object rootModel, object context = null, IDictionary <string, object> settings = null) { var popup = CreatePopup(rootModel, settings); var view = ViewLocator.LocateForModel(rootModel, popup, context); popup.Child = view; popup.SetValue(View.IsGeneratedProperty, true); ViewModelBinder.Bind(rootModel, popup, null); Action.SetTargetWithoutContext(view, rootModel); if (rootModel is IActivate activator) { await activator.ActivateAsync(); } if (rootModel is IDeactivate deactivator) { popup.Closed += async(s, e) => await deactivator.DeactivateAsync(true); } popup.IsOpen = true; popup.CaptureMouse(); }