private void HandleOpenPanel(NavigationPanelEvent navigationPanelEvent) { logger.Debug("Opening Panel {0}", navigationPanelEvent.ViewModel); try { if (!(navigationPanelEvent.View is UIElement uiElement)) { return; } var identifier = navigationPanelEvent.ViewModel.Identifier; var taskPaneExists = this.customTaskPanes.TryGetValue(identifier, out var identifiableCustomTaskPane); if (taskPaneExists) { identifiableCustomTaskPane.CustomTaskPane.Visible = !identifiableCustomTaskPane.CustomTaskPane.Visible; } else { var title = navigationPanelEvent.ViewModel.Caption; var dockPosition = navigationPanelEvent.ViewModel.TargetName.ToDockPosition(); logger.Trace("Create new Task Pane with title {0}", title); var taskPane = this.TaskPaneFactory.CreateCTP("CDP4AddinCE.TaskPaneWpfHostControl", title); taskPane.DockPosition = dockPosition; taskPane.Width = 300; taskPane.Visible = true; if (taskPane is CustomTaskPane customTaskPane) { customTaskPane.VisibleStateChangeEvent += this.CustomTaskPane_VisibleStateChangeEvent; } if (taskPane.ContentControl is TaskPaneWpfHostControl wpfHostControl) { wpfHostControl.SetContent(uiElement); } identifiableCustomTaskPane = new IdentifiableCustomTaskPane(identifier, taskPane); this.customTaskPanes.Add(identifier, identifiableCustomTaskPane); } } catch (Exception ex) { var innerExceptionMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; logger.Fatal(ex, $"handle open panel failed: {ex.Message} - {innerExceptionMessage}"); } }
/// <summary> /// Handles the <see cref="NavigationPanelEvent"/> with <see cref="PanelStatus.Open"/> /// </summary> /// <param name="navigationPanelEvent"> /// The event that carries the view, view-model combination and <see cref="PanelStatus"/> /// </param> private void HandleOpenPanel(NavigationPanelEvent navigationPanelEvent) { logger.Debug("Opening Panel {0}", navigationPanelEvent.ViewModel); try { var uiElement = navigationPanelEvent.View as UIElement; if (uiElement != null) { var identifier = navigationPanelEvent.ViewModel.Identifier; IdentifiableCustomTaskPane identifiableCustomTaskPane = null; var taskPaneExists = this.customTaskPanes.TryGetValue(identifier, out identifiableCustomTaskPane); if (taskPaneExists) { identifiableCustomTaskPane.CustomTaskPane.Visible = !identifiableCustomTaskPane.CustomTaskPane.Visible; } else { var title = navigationPanelEvent.ViewModel.Caption; var dockPosition = navigationPanelEvent.RegionName.ToDockPosition(); logger.Trace("Create new Task Pane with title {0}", title); var taskPane = this.TaskPaneFactory.CreateCTP("CDP4AddinCE.TaskPaneWpfHostControl", title); taskPane.DockPosition = dockPosition; taskPane.Width = 300; taskPane.Visible = true; var wpfHostControl = taskPane.ContentControl as TaskPaneWpfHostControl; if (wpfHostControl != null) { wpfHostControl.SetContent(uiElement); } identifiableCustomTaskPane = new IdentifiableCustomTaskPane(identifier, taskPane); this.customTaskPanes.Add(identifier, identifiableCustomTaskPane); } } } catch (Exception ex) { var innerExceptionMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty; logger.Fatal(ex, string.Format("handle open panel failed: {0} - {1}", ex.Message, innerExceptionMessage)); } }
/// <summary> /// Handles the <see cref="NavigationPanelEvent"/> with <see cref="PanelStatus.Closed"/> /// </summary> /// <param name="navigationPanelEvent"> /// The event that carries the view, view-model combination and <see cref="PanelStatus"/> /// </param> private void HandleClosePanel(NavigationPanelEvent navigationPanelEvent) { logger.Debug("Closing Panel {0}", navigationPanelEvent.ViewModel); try { var identifier = navigationPanelEvent.ViewModel.Identifier; IdentifiableCustomTaskPane identifiableCustomTaskPane = null; var taskPaneExists = this.customTaskPanes.TryGetValue(identifier, out identifiableCustomTaskPane); if (taskPaneExists) { identifiableCustomTaskPane.CustomTaskPane.Visible = false; identifiableCustomTaskPane.Dispose(); this.customTaskPanes.Remove(identifier); } } catch (Exception ex) { logger.Fatal(ex, "handle close panel failed"); } }