Repository navigation
Expand file tree
/
Copy pathMainWindow.UiState.partial.cs
More file actions
53 lines (48 loc) · 2.14 KB
/
Copy pathMainWindow.UiState.partial.cs
File metadata and controls
53 lines (48 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace ThreadPilot
{
using System.Windows;
using ThreadPilot.Services;
public partial class MainWindow
{
// Puts the menu and the window back the way the user left them. A position that is now
// off-screen (unplugged monitor) is pulled back by EnsureDashboardVisibleOnScreen at startup.
private void RestoreUiState()
{
var state = UiStateStore.Current;
this.RootNavigation.IsPaneOpen = state.NavigationPaneOpen;
this.RootNavigation.PaneOpened += (_, _) => UiStateStore.Update(s => s with { NavigationPaneOpen = true });
this.RootNavigation.PaneClosed += (_, _) => UiStateStore.Update(s => s with { NavigationPaneOpen = false });
if (state.WindowWidth is > 0 && state.WindowHeight is > 0 && state.WindowLeft.HasValue && state.WindowTop.HasValue)
{
this.WindowStartupLocation = WindowStartupLocation.Manual;
this.Left = state.WindowLeft.Value;
this.Top = state.WindowTop.Value;
this.Width = state.WindowWidth.Value;
this.Height = state.WindowHeight.Value;
}
if (state.WindowMaximized)
{
this.WindowState = WindowState.Maximized;
}
}
private void SaveWindowPlacement()
{
// RestoreBounds is the normal-size rectangle even while maximized or minimized.
var bounds = this.WindowState == WindowState.Normal
? new Rect(this.Left, this.Top, this.ActualWidth, this.ActualHeight)
: this.RestoreBounds;
if (bounds.IsEmpty || bounds.Width <= 0 || bounds.Height <= 0 || double.IsNaN(bounds.Left))
{
return;
}
UiStateStore.Update(s => s with
{
WindowLeft = bounds.Left,
WindowTop = bounds.Top,
WindowWidth = bounds.Width,
WindowHeight = bounds.Height,
WindowMaximized = this.WindowState == WindowState.Maximized,
});
}
}
}