master
cs 66 lines 2.09 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 NetworkingPage : Page
13 {
14 public NetworkingViewModel ViewModel
15 {
16 get;
17 }
18
19 public NetworkingPage()
20 {
21 ViewModel = App.GetService<NetworkingViewModel>();
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 NetworkingPageRoot.Focus(FocusState.Programmatic);
37 RuntimeHelper.SetupExpanderFocusManagementByName(this, "IgnoredPortsExpander", "IgnoredPortsTextBox");
38 RuntimeHelper.SetupExpanderFocusManagementByName(this, "InitialAutoProxyTimeoutExpander", "InitialAutoProxyTimeoutTextBox");
39 }
40
41 override protected void OnNavigatedFrom(NavigationEventArgs e)
42 {
43 App.GetService<IWslConfigService>().WslConfigChanged -= ViewModel.OnConfigChanged;
44 }
45
46 private void Settings_ResetButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
47 {
48 if (sender == null)
49 {
50 return;
51 }
52
53 RuntimeHelper.TryMoveFocusPreviousControl(sender as Button);
54 }
55
56 private void InitialAutoProxyTimeoutTextBox_TextChanged(object sender, TextChangedEventArgs e)
57 {
58 if (sender == null)
59 {
60 return;
61 }
62
63 TextBox? textBox = sender as TextBox;
64 ViewModel.SetInitialAutoProxyTimeout_ResetEnabled(textBox!.Text);
65 }
66 }