master
cs 58 lines 1.76 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 using Microsoft.UI.Xaml;
4 using Windows.UI.ViewManagement;
5
6 namespace WslSettings;
7
8 public sealed partial class MainWindow : WindowEx
9 {
10 private Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
11
12 private UISettings settings = new UISettings();
13
14 public MainWindow()
15 {
16 InitializeComponent();
17
18 AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/wsl.ico"));
19 Content = null;
20 Title = "Settings_AppDisplayName".GetLocalized();
21
22 // Theme change code picked from https://github.com/microsoft/WinUI-Gallery/pull/1239
23 settings.ColorValuesChanged += Settings_ColorValuesChanged; // cannot use FrameworkElement.ActualThemeChanged event
24 }
25
26 // this handles updating the caption button colors correctly when windows system theme is changed
27 // while the app is open
28 private void Settings_ColorValuesChanged(UISettings sender, object args)
29 {
30 // This calls comes off-thread, hence we will need to dispatch it to current app's thread
31 dispatcherQueue.TryEnqueue(() =>
32 {
33 TitleBarHelper.ApplySystemThemeToCaptionButtons(this);
34 });
35 }
36
37 public void CloseHiddenWindow()
38 {
39 if (!Visible)
40 {
41 Close();
42 }
43 }
44
45 private void Window_Closed(object sender, WindowEventArgs args)
46 {
47 if (App.OOBEWindow == null)
48 {
49 App.MainWindow = null;
50 settings.ColorValuesChanged -= Settings_ColorValuesChanged;
51 }
52 else
53 {
54 args.Handled = true;
55 this.Hide();
56 }
57 }
58 }