| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | |
| 3 | using CommunityToolkit.WinUI.Controls; |
| 4 | using Microsoft.UI.Xaml; |
| 5 | using Microsoft.UI.Xaml.Automation.Peers; |
| 6 | using Microsoft.UI.Xaml.Controls; |
| 7 | using Microsoft.UI.Xaml.Navigation; |
| 8 | using System.Diagnostics; |
| 9 | using WslSettings.Contracts.Services; |
| 10 | using WslSettings.ViewModels.Settings; |
| 11 | |
| 12 | namespace WslSettings.Views.Settings; |
| 13 | |
| 14 | public sealed partial class FileSystemPage : Page |
| 15 | { |
| 16 | public FileSystemViewModel ViewModel |
| 17 | { |
| 18 | get; |
| 19 | } |
| 20 | |
| 21 | public FileSystemPage() |
| 22 | { |
| 23 | ViewModel = App.GetService<FileSystemViewModel>(); |
| 24 | InitializeComponent(); |
| 25 | Settings_ErrorTryAgainLater.RegisterPropertyChangedCallback(TextBlock.VisibilityProperty, (s, e) => |
| 26 | { |
| 27 | if (ViewModel.ErrorVisibility) |
| 28 | { |
| 29 | FrameworkElementAutomationPeer.FromElement(Settings_ErrorTryAgainLater).RaiseAutomationEvent(AutomationEvents.LiveRegionChanged); |
| 30 | } |
| 31 | }); |
| 32 | |
| 33 | this.Loaded += OnPageLoaded; |
| 34 | } |
| 35 | |
| 36 | override protected void OnNavigatedFrom(NavigationEventArgs e) |
| 37 | { |
| 38 | App.GetService<IWslConfigService>().WslConfigChanged -= ViewModel.OnConfigChanged; |
| 39 | } |
| 40 | |
| 41 | private void Settings_ResetButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) |
| 42 | { |
| 43 | if (sender == null) |
| 44 | { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | RuntimeHelper.TryMoveFocusPreviousControl(sender as Button); |
| 49 | } |
| 50 | |
| 51 | private void DefaultVHDSizeTextBox_TextChanged(object sender, TextChangedEventArgs e) |
| 52 | { |
| 53 | if (sender == null) |
| 54 | { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | TextBox? textBox = sender as TextBox; |
| 59 | ViewModel.SetDefaultVHDSize_ResetEnabled(textBox!.Text); |
| 60 | } |
| 61 | |
| 62 | private void OnPageLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) |
| 63 | { |
| 64 | FileSystemPageRoot.Focus(FocusState.Programmatic); |
| 65 | var expander = this.FindName("DefaultVHDSizeExpander") as SettingsExpander; |
| 66 | var textBox = this.FindName("DefaultVHDSizeTextBox") as TextBox; |
| 67 | |
| 68 | Debug.Assert(expander != null, "DefaultVHDSizeExpander not found"); |
| 69 | Debug.Assert(textBox != null, "DefaultVHDSizeTextBox not found"); |
| 70 | |
| 71 | if (expander != null && textBox != null) |
| 72 | { |
| 73 | RuntimeHelper.SetupSettingsExpanderFocusManagement(expander, textBox); |
| 74 | } |
| 75 | } |
| 76 | } |