master
cs 76 lines 2.72 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 using Microsoft.UI.Xaml;
4 using Microsoft.UI.Xaml.Automation.Peers;
5 using Microsoft.UI.Xaml.Controls;
6 using Microsoft.UI.Xaml.Navigation;
7 using WslSettings.Contracts.Services;
8 using WslSettings.ViewModels.Settings;
9
10 namespace WslSettings.Views.Settings;
11
12 public sealed partial class DeveloperPage : Page
13 {
14 public DeveloperViewModel ViewModel
15 {
16 get;
17 }
18
19 public DeveloperPage()
20 {
21 ViewModel = App.GetService<DeveloperViewModel>();
22 InitializeComponent();
23 Settings_ErrorTryAgainLater.RegisterPropertyChangedCallback(TextBlock.VisibilityProperty, (s, e) =>
24 {
25 if (ViewModel.ErrorVisibility)
26 {
27 FrameworkElementAutomationPeer.FromElement(Settings_ErrorTryAgainLater).RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
28 }
29 });
30
31 this.Loaded += OnPageLoaded;
32 }
33
34 private void OnPageLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
35 {
36 DeveloperPageRoot.Focus(FocusState.Programmatic);
37 RuntimeHelper.SetupExpanderFocusManagementByName(this, "CustomKernelPathExpander", "CustomKernelPathTextBox");
38 RuntimeHelper.SetupExpanderFocusManagementByName(this, "CustomKernelModulesPathExpander", "CustomKernelModulesPathTextBox");
39 RuntimeHelper.SetupExpanderFocusManagementByName(this, "CustomSystemDistroPathExpander", "CustomSystemDistroPathTextBox");
40 }
41
42 override protected void OnNavigatedFrom(NavigationEventArgs e)
43 {
44 App.GetService<IWslConfigService>().WslConfigChanged -= ViewModel.OnConfigChanged;
45 }
46
47 public async void CustomKernelPath_Click(object sender, RoutedEventArgs e)
48 {
49 // Open the picker for the user to pick a file
50 Windows.Storage.StorageFile file = await RuntimeHelper.PickSingleFileAsync();
51 if (file != null)
52 {
53 ViewModel.CustomKernelPath = file.Path;
54 }
55 }
56
57 public async void CustomKernelModulesPath_Click(object sender, RoutedEventArgs e)
58 {
59 // Open the picker for the user to pick a file
60 Windows.Storage.StorageFile file = await RuntimeHelper.PickSingleFileAsync([".vhd", ".vhdx"]);
61 if (file != null)
62 {
63 ViewModel.CustomKernelModulesPath = file.Path;
64 }
65 }
66
67 public async void CustomSystemDistroPath_Click(object sender, RoutedEventArgs e)
68 {
69 // Open the picker for the user to pick a file
70 Windows.Storage.StorageFile file = await RuntimeHelper.PickSingleFileAsync([".img", ".vhd"]);
71 if (file != null)
72 {
73 ViewModel.CustomSystemDistroPath = file.Path;
74 }
75 }
76 }