Skip to content

Commit 3b3f923

Browse files
committed
Saves window state between app restarts. Closes #537
1 parent 92ac7f0 commit 3b3f923

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

CompactGUI/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
1717
RenderOptions.BitmapScalingMode="HighQuality" WindowBackdropType="Mica"
1818
WindowCornerPreference="Round" WindowStartupLocation="CenterScreen"
19-
mc:Ignorable="d">
19+
mc:Ignorable="d" Closing="MainWindow_Closing">
2020
<bh:Interaction.Triggers>
2121

2222
<bh:EventTrigger EventName="Closing">

CompactGUI/MainWindow.xaml.vb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ Class MainWindow : Implements INavigationWindow, INotifyPropertyChanged
2626

2727
AddHandler Application.GetService(Of HomeViewModel)().PropertyChanged, AddressOf HVPropertyChanged
2828
AddHandler navigationService.GetNavigationControl.Navigated, AddressOf OnNavigated
29+
30+
If SettingsHandler.AppSettings.WindowWidth > 0 Then
31+
Width = SettingsHandler.AppSettings.WindowWidth
32+
Height = SettingsHandler.AppSettings.WindowHeight
33+
Left = SettingsHandler.AppSettings.WindowLeft
34+
Top = SettingsHandler.AppSettings.WindowTop
35+
If SettingsHandler.AppSettings.WindowState = WindowState.Maximized Then
36+
WindowState = WindowState.Maximized
37+
Else
38+
WindowState = WindowState.Normal
39+
End If
40+
End If
41+
2942
End Sub
3043

3144

@@ -80,4 +93,13 @@ Class MainWindow : Implements INavigationWindow, INotifyPropertyChanged
8093
Public Function Navigate(pageType As Type) As Boolean Implements INavigationWindow.Navigate
8194
Throw New NotImplementedException()
8295
End Function
96+
97+
Private Sub MainWindow_Closing(sender As Object, e As CancelEventArgs)
98+
SettingsHandler.AppSettings.WindowState = WindowState
99+
SettingsHandler.AppSettings.WindowWidth = If(Width > 0, Width, 1300)
100+
SettingsHandler.AppSettings.WindowHeight = If(Height > 0, Height, 700)
101+
SettingsHandler.AppSettings.WindowLeft = Left
102+
SettingsHandler.AppSettings.WindowTop = Top
103+
SettingsHandler.WriteToFile()
104+
End Sub
83105
End Class

CompactGUI/Models/Settings.vb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ Public Class Settings : Inherits ObservableObject
7878
End Property
7979

8080

81+
Public Property WindowTop As Double = 0
82+
Public Property WindowLeft As Double = 0
83+
Public Property WindowWidth As Double = 1300
84+
Public Property WindowHeight As Double = 700
85+
Public Property WindowState As WindowState = WindowState.Normal
86+
87+
8188
Public Shared Async Function AddContextMenus() As Task
8289
Await Task.Run(Sub()
8390
Try

0 commit comments

Comments
 (0)