private void AddWindowControls() { var controlsPanel = new StackPanel { Orientation = Orientation.Horizontal }; var controlsBorder = new Border { Background = new SolidColorBrush(Color.FromArgb(200, 64, 64, 64)), CornerRadius = new CornerRadius(0, 5, 0, 0), HorizontalAlignment = HorizontalAlignment.Stretch, Child = controlsPanel }; MainGrid.Children.Add(controlsBorder); Grid.SetColumn(controlsBorder, 1); var styles = new ResourceDictionary { Source = new Uri("pack://application:,,,/Octgn.JodsEngine;component/Controls/WindowDecorators/OctgnDecoratorResources.xaml", UriKind.RelativeOrAbsolute) }; var buttonStyle = (Style)styles["TitleBarButtonStyle"]; buttonStyle.Setters.Add(new Setter(Control.TemplateProperty, styles["TitleBarButtonTemplate"])); WindowMinimizeButton = new Button { ToolTip = "Minimize", Width = 40, Style = buttonStyle, Content = new Image { Stretch = Stretch.None, Source = new BitmapImage(new Uri("pack://application:,,,/Octgn.JodsEngine;component/Resources/minimize.png")) } }; AutomationProperties.SetName(WindowMinimizeButton, "Minimize"); WindowChrome.SetIsHitTestVisibleInChrome(WindowMinimizeButton, true); WindowMinimizeButton.Click += (sender, args) => { Decorated.WindowState = WindowState.Minimized; }; controlsPanel.Children.Add(WindowMinimizeButton); WindowResizeButton = new Button { ToolTip = "Maximize/Restore", Width = 40, Style = buttonStyle, Content = new Image { Stretch = Stretch.None, Source = new BitmapImage(new Uri("pack://application:,,,/Octgn.JodsEngine;component/Resources/minmax.png")) } }; var binding = new Binding("WindowState") { Source = Decorated, Converter = new WindowStateToToolTipConverter() }; WindowResizeButton.SetBinding(Button.ToolTipProperty, binding); AutomationProperties.SetName(WindowResizeButton, "Resize"); WindowChrome.SetIsHitTestVisibleInChrome(WindowResizeButton, true); WindowResizeButton.Click += (sender, args) => { Decorated.WindowState = (Decorated.WindowState == WindowState.Maximized) ? WindowState.Normal : WindowState.Maximized; }; controlsPanel.Children.Add(WindowResizeButton); WindowCloseButton = new Button { ToolTip = "Close", Width = 40, Style = buttonStyle, Tag = "CLOSE", Content = new Image { Stretch = Stretch.None, Source = new BitmapImage(new Uri("pack://application:,,,/Octgn.JodsEngine;component/Resources/closewindow.png")) } }; AutomationProperties.SetName(WindowCloseButton, "Close"); WindowChrome.SetIsHitTestVisibleInChrome(WindowCloseButton, true); WindowCloseButton.Click += (sender, args) => { Decorated.Close(); }; controlsPanel.Children.Add(WindowCloseButton); }