From 794394ef0c36221251578bf4c49414b4cad127f6 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 22 Jun 2021 10:09:50 +0800 Subject: [PATCH] style: icons for MaximizeWindow/RestoreWindow button --- src/Resources/Icons.xaml | 1 + src/Resources/Styles/ToggleButton.xaml | 34 ++++++++++++++++++++++++++ src/Views/Blame.xaml | 3 ++- src/Views/Blame.xaml.cs | 8 ------ src/Views/Controls/Window.cs | 24 ++++++++++++++++++ src/Views/Histories.xaml | 3 ++- src/Views/Histories.xaml.cs | 8 ------ src/Views/Launcher.xaml | 2 +- src/Views/Launcher.xaml.cs | 8 ------ 9 files changed, 64 insertions(+), 27 deletions(-) diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml index fe73834a..337e2030 100644 --- a/src/Resources/Icons.xaml +++ b/src/Resources/Icons.xaml @@ -13,6 +13,7 @@ M797 486H224c-14 0-25 11-25 25c0 14 11 25 25 25H797c14 0 25-11 25-25c0-14-11-25-25-25z M153 154h768v768h-768v-768zm64 64v640h640v-640h-640z + M256 128l0 192L64 320l0 576 704 0 0-192 192 0L960 128 256 128zM704 832 128 832 128 384l576 0L704 832zM896 640l-128 0L768 320 320 320 320 192l576 0L896 640z M519 459 222 162a37 37 0 10-52 52l297 297L169 809a37 37 0 1052 52l297-297 297 297a37 37 0 1052-52l-297-297 297-297a37 37 0 10-52-52L519 459z M512 597m-1 0a1 1 0 103 0a1 1 0 10-3 0ZM810 393 732 315 448 600 293 444 214 522l156 156 78 78 362-362z M512 0C233 0 7 223 0 500C6 258 190 64 416 64c230 0 416 200 416 448c0 53 43 96 96 96s96-43 96-96c0-283-229-512-512-512zm0 1023c279 0 505-223 512-500c-6 242-190 436-416 436c-230 0-416-200-416-448c0-53-43-96-96-96s-96 43-96 96c0 283 229 512 512 512z diff --git a/src/Resources/Styles/ToggleButton.xaml b/src/Resources/Styles/ToggleButton.xaml index f9c43e97..df40008e 100644 --- a/src/Resources/Styles/ToggleButton.xaml +++ b/src/Resources/Styles/ToggleButton.xaml @@ -142,4 +142,38 @@ + + \ No newline at end of file diff --git a/src/Views/Blame.xaml b/src/Views/Blame.xaml index 0c7f5ba3..85c4cdea 100644 --- a/src/Views/Blame.xaml +++ b/src/Views/Blame.xaml @@ -1,5 +1,6 @@ - + diff --git a/src/Views/Blame.xaml.cs b/src/Views/Blame.xaml.cs index 208d8642..f84ce549 100644 --- a/src/Views/Blame.xaml.cs +++ b/src/Views/Blame.xaml.cs @@ -114,14 +114,6 @@ namespace SourceGit.Views { SystemCommands.MinimizeWindow(this); } - private void MaximizeOrRestore(object sender, RoutedEventArgs e) { - if (WindowState == WindowState.Normal) { - SystemCommands.MaximizeWindow(this); - } else { - SystemCommands.RestoreWindow(this); - } - } - private void Quit(object sender, RoutedEventArgs e) { Close(); } diff --git a/src/Views/Controls/Window.cs b/src/Views/Controls/Window.cs index c1224c37..d152630a 100644 --- a/src/Views/Controls/Window.cs +++ b/src/Views/Controls/Window.cs @@ -8,6 +8,17 @@ namespace SourceGit.Views.Controls { /// public class Window : System.Windows.Window { + public static readonly DependencyProperty IsMaximizedProperty = DependencyProperty.Register( + "IsMaximized", + typeof(bool), + typeof(Window), + new PropertyMetadata(false, OnIsMaximizedChanged)); + + public bool IsMaximized { + get { return (bool)GetValue(IsMaximizedProperty); } + set { SetValue(IsMaximizedProperty, value); } + } + public Window() { Background = FindResource("Brush.Window") as Brush; BorderBrush = FindResource("Brush.WindowBorder") as Brush; @@ -29,13 +40,26 @@ namespace SourceGit.Views.Controls { var content = Content as FrameworkElement; if (WindowState == WindowState.Maximized) { + if (!IsMaximized) IsMaximized = true; BorderThickness = new Thickness(0); content.Margin = new Thickness((SystemParameters.MaximizedPrimaryScreenWidth - SystemParameters.WorkArea.Width) / 2); } else { + if (IsMaximized) IsMaximized = false; BorderThickness = new Thickness(1); content.Margin = new Thickness(0); } }; } + + private static void OnIsMaximizedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { + Window w = d as Window; + if (w != null) { + if (w.IsMaximized) { + SystemCommands.MaximizeWindow(w); + } else { + SystemCommands.RestoreWindow(w); + } + } + } } } diff --git a/src/Views/Histories.xaml b/src/Views/Histories.xaml index 8467dbb9..56e7fe34 100644 --- a/src/Views/Histories.xaml +++ b/src/Views/Histories.xaml @@ -1,5 +1,6 @@ - + diff --git a/src/Views/Histories.xaml.cs b/src/Views/Histories.xaml.cs index 8d8b8d5a..785827c1 100644 --- a/src/Views/Histories.xaml.cs +++ b/src/Views/Histories.xaml.cs @@ -36,14 +36,6 @@ namespace SourceGit.Views { SystemCommands.MinimizeWindow(this); } - private void MaximizeOrRestore(object sender, RoutedEventArgs e) { - if (WindowState == WindowState.Normal) { - SystemCommands.MaximizeWindow(this); - } else { - SystemCommands.RestoreWindow(this); - } - } - private void Quit(object sender, RoutedEventArgs e) { Close(); } diff --git a/src/Views/Launcher.xaml b/src/Views/Launcher.xaml index f6b659f7..cc01bfc4 100644 --- a/src/Views/Launcher.xaml +++ b/src/Views/Launcher.xaml @@ -43,7 +43,7 @@ - + diff --git a/src/Views/Launcher.xaml.cs b/src/Views/Launcher.xaml.cs index 7173ec0e..5e47ef50 100644 --- a/src/Views/Launcher.xaml.cs +++ b/src/Views/Launcher.xaml.cs @@ -57,14 +57,6 @@ namespace SourceGit.Views { SystemCommands.MinimizeWindow(this); } - private void MaximizeOrRestore(object sender, RoutedEventArgs e) { - if (WindowState == WindowState.Normal) { - SystemCommands.MaximizeWindow(this); - } else { - SystemCommands.RestoreWindow(this); - } - } - private void Quit(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); }