/// <summary> /// Creates the window. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="isDialog">Inidcates a dialog window.</param> /// <param name="context">The context.</param> /// <param name="handleShutdownModel">The handle shutdown model.</param> /// <returns></returns> protected virtual Window CreateWindow(object rootModel, bool isDialog, object context, Action <ISubordinate, Action> handleShutdownModel) { var view = EnsureWindow(rootModel, _viewStrategy.GetView(rootModel, null, context), isDialog); _binder.Bind(rootModel, view, context); var screen = rootModel as IPresenter; if (screen != null) { screen.Initialize(); screen.Activate(); view.Activated += delegate { screen.Activate(); }; view.Closing += (s, e) => OnShutdownAttempted(screen, view, handleShutdownModel, e); view.Closed += delegate { screen.Deactivate(); screen.Shutdown(); }; } return(view); }
public void Initialize() { RegisterViews(); var model = m_ServiceLocator.GetInstance <DemoViewPresentationModel>(); var view = m_ViewStrategy.GetView(model, null, null); m_Binder.Bind(model, view, null); m_RegionManager.RegisterViewWithRegion(RegionNames.MainRegion, () => view); }
/// <summary> /// Creates the window. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The context.</param> /// <param name="handleShutdownModel">The handle shutdown model.</param> /// <returns></returns> protected virtual ChildWindow CreateWindow(object rootModel, object context, Action <ISubordinate, Action> handleShutdownModel) { var view = EnsureWindow(rootModel, _viewStrategy.GetView(rootModel, null, context)); _binder.Bind(rootModel, view, context); var presenter = rootModel as IPresenter; if (presenter != null) { presenter.Initialize(); presenter.Activate(); view.Closing += (s, e) => OnShutdownAttempted(presenter, view, handleShutdownModel, e); view.Closed += delegate { presenter.Deactivate(); presenter.Shutdown(); }; } return(view); }
private DockingWindow CreateDockingWindow(object rootModel, DockSite siteTarget) { var view = _viewStrategy.GetView(rootModel, null, null); var presenter = rootModel as IPresenter; if (presenter != null) { if (_cache.ContainsKey(presenter)) { return(_cache[presenter]); } var initialDockDirection = Direction.Left; var metadata = view.GetDockingWindowMetadata(); DockingWindow dockingWindow = new DocumentWindow(siteTarget); if (metadata == null) { dockingWindow.SetBinding( DockingWindow.TitleProperty, new Binding { BindsDirectlyToSource = true, Source = presenter.DisplayName, Mode = BindingMode.OneWay }); } else { if (metadata.IsToolWindow) { var toolWindow = new ToolWindow(siteTarget); #region ToolWindow Property Bindings toolWindow.SetBinding( ToolWindow.CanRaftProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanRaftProperty), Mode = BindingMode.OneWay }); toolWindow.SetBinding( ToolWindow.CanAutoHideProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanAutoHideProperty), Mode = BindingMode.OneWay }); toolWindow.SetBinding( ToolWindow.CanBecomeDocumentProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanBecomeDocumentProperty), Mode = BindingMode.OneWay }); #endregion dockingWindow = toolWindow; } else { dockingWindow.Content = view; } #region DockingWindow Property Bindings dockingWindow.SetBinding( DockingWindow.TitleProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.TitleProperty), Mode = BindingMode.OneWay }); dockingWindow.SetBinding( DockingWindow.CanCloseProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanCloseProperty), Mode = BindingMode.OneWay }); dockingWindow.SetBinding( DockingWindow.CanDragProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanDragProperty), Mode = BindingMode.OneWay }); dockingWindow.SetBinding( DockingWindow.CanAttachProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanAttachProperty), Mode = BindingMode.OneWay }); dockingWindow.SetBinding( DockingWindow.CanDockLeftProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanDockLeftProperty), Mode = BindingMode.OneWay }); dockingWindow.SetBinding( DockingWindow.CanDockRightProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanDockRightProperty), Mode = BindingMode.OneWay }); dockingWindow.SetBinding( DockingWindow.CanDockTopProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanDockTopProperty), Mode = BindingMode.OneWay }); dockingWindow.SetBinding( DockingWindow.CanDockBottomProperty, new Binding { Source = metadata, Path = new PropertyPath(DockingWindowMetadata.CanDockBottomProperty), Mode = BindingMode.OneWay }); #endregion switch (metadata.DefaultDock) { case DockSiteDock.Left: initialDockDirection = Direction.Left; break; case DockSiteDock.Right: initialDockDirection = Direction.Right; break; case DockSiteDock.Top: initialDockDirection = Direction.Top; break; case DockSiteDock.Bottom: initialDockDirection = Direction.Bottom; break; case DockSiteDock.Content: initialDockDirection = Direction.Content; break; } if (dockingWindow is ToolWindow) { var dockTarget = GetDockTarget(siteTarget, initialDockDirection); if (metadata.Undock) { dockingWindow.Float(metadata.DefaultSize); } else { ((ToolWindow)dockingWindow).Dock(dockTarget, (metadata.CreateNewDockingGroup) && !dockTarget.Equals(siteTarget) ? Direction.Content : initialDockDirection); } } } _binder.Bind(rootModel, view, null); dockingWindow.Content = view; presenter.Initialize(); _cache[presenter] = dockingWindow; return(_cache[presenter]); } throw new Exception(Properties.Resources.NullRootModelException); }