From 57dccce1bf04664b7e49721ab5e720a8d21dca18 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 15 May 2025 18:35:57 +0800 Subject: [PATCH 1/5] Fix setting window navigation update issue & Check view model null instead of IsInitialized flag --- .../Resources/Pages/WelcomePage1.xaml.cs | 2 +- .../Resources/Pages/WelcomePage2.xaml.cs | 2 +- .../Resources/Pages/WelcomePage3.xaml.cs | 2 +- .../Resources/Pages/WelcomePage4.xaml.cs | 2 +- .../Resources/Pages/WelcomePage5.xaml.cs | 2 +- .../Views/SettingsPaneAbout.xaml.cs | 8 ++++- .../Views/SettingsPaneGeneral.xaml.cs | 8 ++++- .../Views/SettingsPaneHotkey.xaml.cs | 8 ++++- .../Views/SettingsPanePluginStore.xaml.cs | 7 +++- .../Views/SettingsPanePlugins.xaml.cs | 7 +++- .../Views/SettingsPaneProxy.xaml.cs | 8 ++++- .../Views/SettingsPaneTheme.xaml.cs | 8 ++++- Flow.Launcher/SettingWindow.xaml.cs | 33 +++++++++++++++++-- .../ViewModel/SettingWindowViewModel.cs | 18 +++++++++- 14 files changed, 100 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs index a3b008206d6..1b1dd21e9e9 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs @@ -14,7 +14,7 @@ public partial class WelcomePage1 protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); diff --git a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs index a63edbcda7c..7408d8a14f0 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs @@ -16,7 +16,7 @@ public partial class WelcomePage2 protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); diff --git a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs index 4a6610e6173..bd14bf0f7b9 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs @@ -12,7 +12,7 @@ public partial class WelcomePage3 protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); diff --git a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs index 1ee3284d22e..b20e4ce0a47 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs @@ -12,7 +12,7 @@ public partial class WelcomePage4 protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); diff --git a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs index 6328c991449..84d298966d7 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs @@ -15,7 +15,7 @@ public partial class WelcomePage5 protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs index e57cba6d409..93515caec5b 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs @@ -1,21 +1,27 @@ using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneAbout { private SettingsPaneAboutViewModel _viewModel = null!; + private SettingWindowViewModel _settingViewModel = null; protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); + _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneAbout); base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs index 31653962dfd..fa3406bd914 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs @@ -1,21 +1,27 @@ using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneGeneral { private SettingsPaneGeneralViewModel _viewModel = null!; + private SettingWindowViewModel _settingViewModel = null; protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); + _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneGeneral); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs index 8b757bd60a5..e590dc9a82a 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs @@ -1,21 +1,27 @@ using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneHotkey { private SettingsPaneHotkeyViewModel _viewModel = null!; + private SettingWindowViewModel _settingViewModel = null; protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); + _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneHotkey); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs index 5ddfe465009..aa6900dae6f 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs @@ -11,16 +11,21 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPanePluginStore { private SettingsPanePluginStoreViewModel _viewModel = null!; + private SettingWindowViewModel _settingViewModel = null; protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); + _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } _viewModel.PropertyChanged += ViewModel_PropertyChanged; + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPanePluginStore); base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs index e9490804ab5..6424aabdfeb 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs @@ -11,16 +11,21 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPanePlugins { private SettingsPanePluginsViewModel _viewModel = null!; + private SettingWindowViewModel _settingViewModel = null; protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); + _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } _viewModel.PropertyChanged += ViewModel_PropertyChanged; + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPanePlugins); base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs index 258f2a4adbf..c89a050f5da 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs @@ -1,21 +1,27 @@ using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneProxy { private SettingsPaneProxyViewModel _viewModel = null!; + private SettingWindowViewModel _settingViewModel = null; protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); + _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneProxy); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index cee8e4ae468..8759c8efc80 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -1,21 +1,27 @@ using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneTheme { private SettingsPaneThemeViewModel _viewModel = null!; + private SettingWindowViewModel _settingViewModel = null; protected override void OnNavigatedTo(NavigationEventArgs e) { - if (!IsInitialized) + if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); + _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneTheme); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index cf84317acb0..14e4343e3c8 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -18,6 +19,7 @@ public partial class SettingWindow #region Private Fields private readonly Settings _settings; + private readonly SettingWindowViewModel _viewModel; #endregion @@ -26,8 +28,8 @@ public partial class SettingWindow public SettingWindow() { _settings = Ioc.Default.GetRequiredService(); - var viewModel = Ioc.Default.GetRequiredService(); - DataContext = viewModel; + _viewModel = Ioc.Default.GetRequiredService(); + DataContext = _viewModel; InitializeComponent(); UpdatePositionAndState(); @@ -48,10 +50,37 @@ private void OnLoaded(object sender, RoutedEventArgs e) hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here UpdatePositionAndState(); + + _viewModel.PropertyChanged += ViewModel_PropertyChanged; + } + + // Sometimes the navigation is not triggered by button click, + // so we need to update the selected item here + private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + switch (e.PropertyName) + { + case nameof(SettingWindowViewModel.PageType): + var selectedIndex = _viewModel.PageType.Name switch + { + nameof(SettingsPaneGeneral) => 0, + nameof(SettingsPanePlugins) => 1, + nameof(SettingsPanePluginStore) => 2, + nameof(SettingsPaneTheme) => 3, + nameof(SettingsPaneHotkey) => 4, + nameof(SettingsPaneProxy) => 5, + nameof(SettingsPaneAbout) => 6, + _ => 0 + }; + NavView.SelectedItem = NavView.MenuItems[selectedIndex]; + break; + } } private void OnClosed(object sender, EventArgs e) { + _viewModel.PropertyChanged -= ViewModel_PropertyChanged; + // If app is exiting, settings save is not needed because main window closing event will handle this if (App.Exiting) return; // Save settings when window is closed diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 17a1a2b50f1..9e7eaf6e86a 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -1,5 +1,7 @@ -using Flow.Launcher.Infrastructure.UserSettings; +using System; +using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using Flow.Launcher.SettingPages.Views; namespace Flow.Launcher.ViewModel; @@ -12,6 +14,20 @@ public SettingWindowViewModel(Settings settings) _settings = settings; } + private Type _pageType = typeof(SettingsPaneGeneral); + public Type PageType + { + get => _pageType; + set + { + if (_pageType != value) + { + _pageType = value; + OnPropertyChanged(); + } + } + } + public double SettingWindowWidth { get => _settings.SettingWindowWidth; From 1a67c8906b42a9e0bffba8a497a57703de7ae7e8 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 15 May 2025 19:36:45 +0800 Subject: [PATCH 2/5] Fix component initialization issue --- Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs | 4 ++++ Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs | 4 ++++ Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs | 4 ++++ Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs | 4 ++++ Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs | 4 ++++ Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs | 4 ++++ Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs | 4 ++++ Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs | 4 ++++ .../SettingPages/Views/SettingsPanePluginStore.xaml.cs | 4 ++++ Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs | 4 ++++ Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs | 4 ++++ Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs | 4 ++++ 12 files changed, 48 insertions(+) diff --git a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs index 1b1dd21e9e9..3199e81b776 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs @@ -14,10 +14,14 @@ public partial class WelcomePage1 protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs index 7408d8a14f0..1eef9fc8c79 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs @@ -16,10 +16,14 @@ public partial class WelcomePage2 protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs index bd14bf0f7b9..d27368aa1b4 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs @@ -12,10 +12,14 @@ public partial class WelcomePage3 protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs index b20e4ce0a47..b0999504b31 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs @@ -12,10 +12,14 @@ public partial class WelcomePage4 protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs index 84d298966d7..2ece4ce8800 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs @@ -15,10 +15,14 @@ public partial class WelcomePage5 protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { Settings = Ioc.Default.GetRequiredService(); _viewModel = Ioc.Default.GetRequiredService(); + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs index 93515caec5b..00426546ab5 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs @@ -12,11 +12,15 @@ public partial class SettingsPaneAbout protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs index fa3406bd914..524e4f5f581 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs @@ -12,11 +12,15 @@ public partial class SettingsPaneGeneral protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs index e590dc9a82a..53a639aa564 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs @@ -12,11 +12,15 @@ public partial class SettingsPaneHotkey protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs index aa6900dae6f..34cd33ec10b 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs @@ -15,11 +15,15 @@ public partial class SettingsPanePluginStore protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; + } + if (!IsInitialized) + { InitializeComponent(); } _viewModel.PropertyChanged += ViewModel_PropertyChanged; diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs index 6424aabdfeb..94e0d24a24c 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs @@ -15,11 +15,15 @@ public partial class SettingsPanePlugins protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; + } + if (!IsInitialized) + { InitializeComponent(); } _viewModel.PropertyChanged += ViewModel_PropertyChanged; diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs index c89a050f5da..aa47383e850 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs @@ -12,11 +12,15 @@ public partial class SettingsPaneProxy protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index 8759c8efc80..215a8c70c40 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -12,11 +12,15 @@ public partial class SettingsPaneTheme protected override void OnNavigatedTo(NavigationEventArgs e) { + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; + } + if (!IsInitialized) + { InitializeComponent(); } // Sometimes the navigation is not triggered by button click, From 5b17fad67cab25ba9da890d188c988f03835f74a Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 15 May 2025 19:51:30 +0800 Subject: [PATCH 3/5] Fix duplicated value change --- Flow.Launcher/SettingWindow.xaml.cs | 1 + Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 14e4343e3c8..d8444d45d5c 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -263,6 +263,7 @@ private void NavigationView_SelectionChanged(NavigationView sender, NavigationVi nameof(About) => typeof(SettingsPaneAbout), _ => typeof(SettingsPaneGeneral) }; + _viewModel.SetPageType(pageType); ContentFrame.Navigate(pageType); } } diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 9e7eaf6e86a..5b130eb6d24 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -14,6 +14,11 @@ public SettingWindowViewModel(Settings settings) _settings = settings; } + public void SetPageType(Type pageType) + { + _pageType = pageType; + } + private Type _pageType = typeof(SettingsPaneGeneral); public Type PageType { From d0e799b8edaf7378d38a7ef8bf71311dda29e262 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 15 May 2025 20:16:50 +0800 Subject: [PATCH 4/5] Fix double navigation issue --- .../SettingPages/Views/SettingsPaneAbout.xaml.cs | 10 +++++----- .../SettingPages/Views/SettingsPaneGeneral.xaml.cs | 10 +++++----- .../SettingPages/Views/SettingsPaneHotkey.xaml.cs | 10 +++++----- .../Views/SettingsPanePluginStore.xaml.cs | 10 +++++----- .../SettingPages/Views/SettingsPanePlugins.xaml.cs | 10 +++++----- .../SettingPages/Views/SettingsPaneProxy.xaml.cs | 10 +++++----- .../SettingPages/Views/SettingsPaneTheme.xaml.cs | 10 +++++----- Flow.Launcher/SettingWindow.xaml.cs | 11 ++++++++--- Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 8 +++++--- 9 files changed, 48 insertions(+), 41 deletions(-) diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs index 00426546ab5..47532b243eb 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs @@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneAbout { private SettingsPaneAboutViewModel _viewModel = null!; - private SettingWindowViewModel _settingViewModel = null; + private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneAbout); + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); - _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; } if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page type - _settingViewModel.PageType = typeof(SettingsPaneAbout); base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs index 524e4f5f581..753cb7b0e3b 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs @@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneGeneral { private SettingsPaneGeneralViewModel _viewModel = null!; - private SettingWindowViewModel _settingViewModel = null; + private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneGeneral); + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); - _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; } if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page type - _settingViewModel.PageType = typeof(SettingsPaneGeneral); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs index 53a639aa564..202869bc5d0 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs @@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneHotkey { private SettingsPaneHotkeyViewModel _viewModel = null!; - private SettingWindowViewModel _settingViewModel = null; + private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneHotkey); + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); - _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; } if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page type - _settingViewModel.PageType = typeof(SettingsPaneHotkey); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs index 34cd33ec10b..c0a77957ac8 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs @@ -11,15 +11,18 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPanePluginStore { private SettingsPanePluginStoreViewModel _viewModel = null!; - private SettingWindowViewModel _settingViewModel = null; + private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPanePluginStore); + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); - _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; } if (!IsInitialized) @@ -27,9 +30,6 @@ protected override void OnNavigatedTo(NavigationEventArgs e) InitializeComponent(); } _viewModel.PropertyChanged += ViewModel_PropertyChanged; - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page type - _settingViewModel.PageType = typeof(SettingsPanePluginStore); base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs index 94e0d24a24c..f486a3443ce 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs @@ -11,15 +11,18 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPanePlugins { private SettingsPanePluginsViewModel _viewModel = null!; - private SettingWindowViewModel _settingViewModel = null; + private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPanePlugins); + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); - _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; } if (!IsInitialized) @@ -27,9 +30,6 @@ protected override void OnNavigatedTo(NavigationEventArgs e) InitializeComponent(); } _viewModel.PropertyChanged += ViewModel_PropertyChanged; - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page type - _settingViewModel.PageType = typeof(SettingsPanePlugins); base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs index aa47383e850..3e617229d4f 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs @@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneProxy { private SettingsPaneProxyViewModel _viewModel = null!; - private SettingWindowViewModel _settingViewModel = null; + private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneProxy); + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); - _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; } if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page type - _settingViewModel.PageType = typeof(SettingsPaneProxy); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index 215a8c70c40..170003994ed 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views; public partial class SettingsPaneTheme { private SettingsPaneThemeViewModel _viewModel = null!; - private SettingWindowViewModel _settingViewModel = null; + private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page type + _settingViewModel.PageType = typeof(SettingsPaneTheme); + // If the navigation is not triggered by button click, view model will be null again if (_viewModel == null) { _viewModel = Ioc.Default.GetRequiredService(); - _settingViewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; } if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page type - _settingViewModel.PageType = typeof(SettingsPaneTheme); base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index d8444d45d5c..ebbb3841482 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -241,6 +241,7 @@ private void NavigationView_SelectionChanged(NavigationView sender, NavigationVi { if (args.IsSettingsSelected) { + _viewModel.SetPageType(typeof(SettingsPaneGeneral)); ContentFrame.Navigate(typeof(SettingsPaneGeneral)); } else @@ -263,8 +264,11 @@ private void NavigationView_SelectionChanged(NavigationView sender, NavigationVi nameof(About) => typeof(SettingsPaneAbout), _ => typeof(SettingsPaneGeneral) }; - _viewModel.SetPageType(pageType); - ContentFrame.Navigate(pageType); + // Only navigate if the page type changes to fix navigation forward/back issue + if (_viewModel.SetPageType(pageType)) + { + ContentFrame.Navigate(pageType); + } } } @@ -282,7 +286,8 @@ private void NavView_Loaded(object sender, RoutedEventArgs e) private void ContentFrame_Loaded(object sender, RoutedEventArgs e) { - NavView.SelectedItem ??= NavView.MenuItems[0]; /* Set First Page */ + _viewModel.SetPageType(null); // Set page type to null so that NavigationView_SelectionChanged can navigate the frame + NavView.SelectedItem = NavView.MenuItems[0]; /* Set First Page */ } #endregion diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 5b130eb6d24..1134a81b896 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -1,7 +1,6 @@ using System; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; -using Flow.Launcher.SettingPages.Views; namespace Flow.Launcher.ViewModel; @@ -14,12 +13,15 @@ public SettingWindowViewModel(Settings settings) _settings = settings; } - public void SetPageType(Type pageType) + public bool SetPageType(Type pageType) { + if (_pageType == pageType) return false; + _pageType = pageType; + return true; } - private Type _pageType = typeof(SettingsPaneGeneral); + private Type _pageType = null; public Type PageType { get => _pageType; From ad94ebadcfc8c175c4406be9b2b055fe448cacd2 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 15 May 2025 20:23:38 +0800 Subject: [PATCH 5/5] Fix possible issue in welcome pages --- .../Resources/Pages/WelcomePage1.xaml.cs | 17 ++++++----------- .../Resources/Pages/WelcomePage2.xaml.cs | 17 ++++++----------- .../Resources/Pages/WelcomePage3.xaml.cs | 17 ++++++----------- .../Resources/Pages/WelcomePage4.xaml.cs | 17 ++++++----------- .../Resources/Pages/WelcomePage5.xaml.cs | 17 ++++++----------- 5 files changed, 30 insertions(+), 55 deletions(-) diff --git a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs index 3199e81b776..16252086e2b 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs @@ -9,24 +9,19 @@ namespace Flow.Launcher.Resources.Pages { public partial class WelcomePage1 { - public Settings Settings { get; private set; } - private WelcomeViewModel _viewModel; + public Settings Settings { get; } = Ioc.Default.GetRequiredService(); + private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { - // If the navigation is not triggered by button click, view model will be null again - if (_viewModel == null) - { - Settings = Ioc.Default.GetRequiredService(); - _viewModel = Ioc.Default.GetRequiredService(); - } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + _viewModel.PageNum = 1; + if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page number - _viewModel.PageNum = 1; base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs index 1eef9fc8c79..37767f1285f 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs @@ -11,24 +11,19 @@ namespace Flow.Launcher.Resources.Pages { public partial class WelcomePage2 { - public Settings Settings { get; private set; } - private WelcomeViewModel _viewModel; + public Settings Settings { get; } = Ioc.Default.GetRequiredService(); + private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { - // If the navigation is not triggered by button click, view model will be null again - if (_viewModel == null) - { - Settings = Ioc.Default.GetRequiredService(); - _viewModel = Ioc.Default.GetRequiredService(); - } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + _viewModel.PageNum = 2; + if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page number - _viewModel.PageNum = 2; base.OnNavigatedTo(e); } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs index d27368aa1b4..4c3184f8c57 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs @@ -7,24 +7,19 @@ namespace Flow.Launcher.Resources.Pages { public partial class WelcomePage3 { - public Settings Settings { get; private set; } - private WelcomeViewModel _viewModel; + public Settings Settings { get; } = Ioc.Default.GetRequiredService(); + private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { - // If the navigation is not triggered by button click, view model will be null again - if (_viewModel == null) - { - Settings = Ioc.Default.GetRequiredService(); - _viewModel = Ioc.Default.GetRequiredService(); - } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + _viewModel.PageNum = 3; + if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page number - _viewModel.PageNum = 3; base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs index b0999504b31..63c9b9a7afa 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs @@ -7,24 +7,19 @@ namespace Flow.Launcher.Resources.Pages { public partial class WelcomePage4 { - public Settings Settings { get; private set; } - private WelcomeViewModel _viewModel; + public Settings Settings { get; } = Ioc.Default.GetRequiredService(); + private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { - // If the navigation is not triggered by button click, view model will be null again - if (_viewModel == null) - { - Settings = Ioc.Default.GetRequiredService(); - _viewModel = Ioc.Default.GetRequiredService(); - } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + _viewModel.PageNum = 4; + if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page number - _viewModel.PageNum = 4; base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs index 2ece4ce8800..8db0a9f7e08 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs @@ -10,24 +10,19 @@ namespace Flow.Launcher.Resources.Pages { public partial class WelcomePage5 { - public Settings Settings { get; private set; } - private WelcomeViewModel _viewModel; + public Settings Settings { get; } = Ioc.Default.GetRequiredService(); + private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService(); protected override void OnNavigatedTo(NavigationEventArgs e) { - // If the navigation is not triggered by button click, view model will be null again - if (_viewModel == null) - { - Settings = Ioc.Default.GetRequiredService(); - _viewModel = Ioc.Default.GetRequiredService(); - } + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + _viewModel.PageNum = 5; + if (!IsInitialized) { InitializeComponent(); } - // Sometimes the navigation is not triggered by button click, - // so we need to reset the page number - _viewModel.PageNum = 5; base.OnNavigatedTo(e); }