From f04c01b878c7fdf7e3a3edd42dbd6299c5e77c9a Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 4 Jan 2022 14:52:13 +0800 Subject: [PATCH] feature: remember window state --- src/Models/Preference.cs | 6 ++++++ src/Views/Controls/Window.cs | 8 +++++--- src/Views/Launcher.xaml | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs index 077733ab..4e34adfb 100644 --- a/src/Models/Preference.cs +++ b/src/Models/Preference.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Text.Json; using System.Text.Json.Serialization; +using System.Windows; namespace SourceGit.Models { @@ -125,6 +126,11 @@ namespace SourceGit.Models { /// public double Height { get; set; } = 600; + /// + /// 保存上次关闭时是否最大化中 + /// + public WindowState State { get; set; } = WindowState.Normal; + /// /// 将提交信息面板与提交记录左右排布 /// diff --git a/src/Views/Controls/Window.cs b/src/Views/Controls/Window.cs index aaf9c3dd..24dfaa64 100644 --- a/src/Views/Controls/Window.cs +++ b/src/Views/Controls/Window.cs @@ -25,7 +25,11 @@ namespace SourceGit.Views.Controls { public Window() { Style = FindResource("Style.Window") as Style; - Loaded += (_, __) => adornerLayer = AdornerLayer.GetAdornerLayer(Content as FrameworkElement); + + Loaded += (_, __) => { + adornerLayer = AdornerLayer.GetAdornerLayer(Content as FrameworkElement); + OnStateChanged(null); + }; } public static void AddAdorner(FrameworkElement windowContext, Adorner adorner) { @@ -50,8 +54,6 @@ namespace SourceGit.Views.Controls { } protected override void OnStateChanged(EventArgs e) { - base.OnStateChanged(e); - if (WindowState == WindowState.Maximized) { if (!IsMaximized) IsMaximized = true; BorderThickness = new Thickness(0); diff --git a/src/Views/Launcher.xaml b/src/Views/Launcher.xaml index 1fab17a8..afbd321c 100644 --- a/src/Views/Launcher.xaml +++ b/src/Views/Launcher.xaml @@ -14,6 +14,7 @@ Title="{DynamicResource Text.About.Title}" Width="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Width, Mode=TwoWay}" Height="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Height, Mode=TwoWay}" + WindowState="{Binding Source={x:Static models:Preference.Instance}, Path=Window.State, Mode=TwoWay}" Closing="OnClosing">