/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); // OnAplyTemplate is executed then theme is changed if (adorner != null) { /*bool isOpened = IsOpen; * if (isOpened) * { * Hide(); * IsOpen = false; * } * Dispatcher.BeginInvoke(DispatcherPriority.Render, (ThreadStart)(() => { * adorner.Clear(); * adorner = null; * if (isOpened) * { * Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (ThreadStart)(() => { IsOpen = true; })); * } * })); */ if (IsOpen) { Hide(); IsOpen = false; // Clear adorner adorner.Clear(); adorner = null; /*// Remove adorner * AdornerLayer layer = GetAdornerLayer(this); * layer.Remove(adorner); * // Clear adorner * adorner.Clear(); * adorner = null; * // Create new adorner * Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (ThreadStart)(() => * { * if (adorner == null) * { * if (DesignerProperties.GetIsInDesignMode(this)) * { * // TODO: in design mode it is required to use design time adorner * FrameworkElement topLevelElement = (FrameworkElement)VisualTreeHelper.GetParent(this); * double topOffset = this.TranslatePoint(new Point(0, this.ActualHeight), topLevelElement).Y; * adorner = new BackstageAdorner(topLevelElement, Content, topOffset); * } * else * { * Window mainWindow = Window.GetWindow(this); * if (mainWindow == null) return; * FrameworkElement topLevelElement = (FrameworkElement)mainWindow.Content; * if (topLevelElement == null) return; * double topOffset = this.TranslatePoint(new Point(0, this.ActualHeight), topLevelElement).Y; * adorner = new BackstageAdorner(topLevelElement, this.Content, topOffset); * } * } * layer.Add(adorner); * }));*/ } else { // Clear adorner adorner.Clear(); adorner = null; } } }
// Opens backstage on an Adorner layer private void Show() { if (!this.IsLoaded) { this.Loaded += this.OnDelayedShow; return; } if (this.Content == null) { return; } var layer = GetAdornerLayer(this); if (adorner == null) { if (DesignerProperties.GetIsInDesignMode(this)) { // TODO: in design mode it is required to use design time adorner var topLevelElement = (FrameworkElement)VisualTreeHelper.GetParent(this); var topOffset = this.TranslatePoint(new Point(0, this.ActualHeight), topLevelElement).Y; adorner = new BackstageAdorner(topLevelElement, Content, topOffset); } else { var mainWindow = Window.GetWindow(this); if (mainWindow == null) { return; } var topLevelElement = (FrameworkElement)mainWindow.Content; if (topLevelElement == null) { return; } var topOffset = this.TranslatePoint(new Point(0, this.ActualHeight), topLevelElement).Y; adorner = new BackstageAdorner(topLevelElement, this.Content, topOffset); } } layer.Add(adorner); var ribbon = this.FindRibbon(); if (ribbon != null) { ribbon.TabControl.IsDropDownOpen = false; ribbon.TabControl.HighlightSelectedItem = false; ribbon.TabControl.RequestBackstageClose += this.OnTabControlRequestBackstageClose; // Disable QAT & title bar if (ribbon.QuickAccessToolBar != null) { ribbon.QuickAccessToolBar.IsEnabled = false; } if (ribbon.TitleBar != null) { ribbon.TitleBar.IsEnabled = false; } } var window = Window.GetWindow(this); if (window != null) { window.KeyDown += this.OnBackstageEscapeKeyDown; savedMinWidth = window.MinWidth; savedMinHeight = window.MinHeight; this.SaveWindowSize(window); if (savedMinWidth < 500) { window.MinWidth = 500; } if (savedMinHeight < 400) { window.MinHeight = 400; } window.SizeChanged += this.OnWindowSizeChanged; // We have to collapse WindowsFormsHost while Backstage is open this.CollapseWindowsFormsHosts(window); } var content = this.Content as IInputElement; if (content != null) { content.Focus(); } }