Skip to content

Commit e80d191

Browse files
authored
Merge pull request #3547 from Flow-Launcher/setting_window_navigation_issue
Fix setting window navigation update issue
2 parents c591011 + ad94eba commit e80d191

14 files changed

+168
-47
lines changed

Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ namespace Flow.Launcher.Resources.Pages
99
{
1010
public partial class WelcomePage1
1111
{
12-
public Settings Settings { get; private set; }
13-
private WelcomeViewModel _viewModel;
12+
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
13+
private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
1414

1515
protected override void OnNavigatedTo(NavigationEventArgs e)
1616
{
17+
// Sometimes the navigation is not triggered by button click,
18+
// so we need to reset the page number
19+
_viewModel.PageNum = 1;
20+
1721
if (!IsInitialized)
1822
{
19-
Settings = Ioc.Default.GetRequiredService<Settings>();
20-
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
2123
InitializeComponent();
2224
}
23-
// Sometimes the navigation is not triggered by button click,
24-
// so we need to reset the page number
25-
_viewModel.PageNum = 1;
2625
base.OnNavigatedTo(e);
2726
}
2827

Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@ namespace Flow.Launcher.Resources.Pages
1111
{
1212
public partial class WelcomePage2
1313
{
14-
public Settings Settings { get; private set; }
15-
private WelcomeViewModel _viewModel;
14+
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
15+
private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
1616

1717
protected override void OnNavigatedTo(NavigationEventArgs e)
1818
{
19+
// Sometimes the navigation is not triggered by button click,
20+
// so we need to reset the page number
21+
_viewModel.PageNum = 2;
22+
1923
if (!IsInitialized)
2024
{
21-
Settings = Ioc.Default.GetRequiredService<Settings>();
22-
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
2325
InitializeComponent();
2426
}
25-
// Sometimes the navigation is not triggered by button click,
26-
// so we need to reset the page number
27-
_viewModel.PageNum = 2;
2827
base.OnNavigatedTo(e);
2928
}
3029

Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ namespace Flow.Launcher.Resources.Pages
77
{
88
public partial class WelcomePage3
99
{
10-
public Settings Settings { get; private set; }
11-
private WelcomeViewModel _viewModel;
10+
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
11+
private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
1212

1313
protected override void OnNavigatedTo(NavigationEventArgs e)
1414
{
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page number
17+
_viewModel.PageNum = 3;
18+
1519
if (!IsInitialized)
1620
{
17-
Settings = Ioc.Default.GetRequiredService<Settings>();
18-
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
1921
InitializeComponent();
2022
}
21-
// Sometimes the navigation is not triggered by button click,
22-
// so we need to reset the page number
23-
_viewModel.PageNum = 3;
2423
base.OnNavigatedTo(e);
2524
}
2625
}

Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ namespace Flow.Launcher.Resources.Pages
77
{
88
public partial class WelcomePage4
99
{
10-
public Settings Settings { get; private set; }
11-
private WelcomeViewModel _viewModel;
10+
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
11+
private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
1212

1313
protected override void OnNavigatedTo(NavigationEventArgs e)
1414
{
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page number
17+
_viewModel.PageNum = 4;
18+
1519
if (!IsInitialized)
1620
{
17-
Settings = Ioc.Default.GetRequiredService<Settings>();
18-
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
1921
InitializeComponent();
2022
}
21-
// Sometimes the navigation is not triggered by button click,
22-
// so we need to reset the page number
23-
_viewModel.PageNum = 4;
2423
base.OnNavigatedTo(e);
2524
}
2625
}

Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ namespace Flow.Launcher.Resources.Pages
1010
{
1111
public partial class WelcomePage5
1212
{
13-
public Settings Settings { get; private set; }
14-
private WelcomeViewModel _viewModel;
13+
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
14+
private readonly WelcomeViewModel _viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
1515

1616
protected override void OnNavigatedTo(NavigationEventArgs e)
1717
{
18+
// Sometimes the navigation is not triggered by button click,
19+
// so we need to reset the page number
20+
_viewModel.PageNum = 5;
21+
1822
if (!IsInitialized)
1923
{
20-
Settings = Ioc.Default.GetRequiredService<Settings>();
21-
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
2224
InitializeComponent();
2325
}
24-
// Sometimes the navigation is not triggered by button click,
25-
// so we need to reset the page number
26-
_viewModel.PageNum = 5;
2726
base.OnNavigatedTo(e);
2827
}
2928

Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
using System.Windows.Navigation;
22
using CommunityToolkit.Mvvm.DependencyInjection;
33
using Flow.Launcher.SettingPages.ViewModels;
4+
using Flow.Launcher.ViewModel;
45

56
namespace Flow.Launcher.SettingPages.Views;
67

78
public partial class SettingsPaneAbout
89
{
910
private SettingsPaneAboutViewModel _viewModel = null!;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1012

1113
protected override void OnNavigatedTo(NavigationEventArgs e)
1214
{
13-
if (!IsInitialized)
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneAbout);
18+
19+
// If the navigation is not triggered by button click, view model will be null again
20+
if (_viewModel == null)
1421
{
1522
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneAboutViewModel>();
1623
DataContext = _viewModel;
24+
}
25+
if (!IsInitialized)
26+
{
1727
InitializeComponent();
1828
}
1929
base.OnNavigatedTo(e);

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
using System.Windows.Navigation;
22
using CommunityToolkit.Mvvm.DependencyInjection;
33
using Flow.Launcher.SettingPages.ViewModels;
4+
using Flow.Launcher.ViewModel;
45

56
namespace Flow.Launcher.SettingPages.Views;
67

78
public partial class SettingsPaneGeneral
89
{
910
private SettingsPaneGeneralViewModel _viewModel = null!;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1012

1113
protected override void OnNavigatedTo(NavigationEventArgs e)
1214
{
13-
if (!IsInitialized)
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneGeneral);
18+
19+
// If the navigation is not triggered by button click, view model will be null again
20+
if (_viewModel == null)
1421
{
1522
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneGeneralViewModel>();
1623
DataContext = _viewModel;
24+
}
25+
if (!IsInitialized)
26+
{
1727
InitializeComponent();
1828
}
1929
base.OnNavigatedTo(e);

Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
using System.Windows.Navigation;
22
using CommunityToolkit.Mvvm.DependencyInjection;
33
using Flow.Launcher.SettingPages.ViewModels;
4+
using Flow.Launcher.ViewModel;
45

56
namespace Flow.Launcher.SettingPages.Views;
67

78
public partial class SettingsPaneHotkey
89
{
910
private SettingsPaneHotkeyViewModel _viewModel = null!;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1012

1113
protected override void OnNavigatedTo(NavigationEventArgs e)
1214
{
13-
if (!IsInitialized)
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneHotkey);
18+
19+
// If the navigation is not triggered by button click, view model will be null again
20+
if (_viewModel == null)
1421
{
1522
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneHotkeyViewModel>();
1623
DataContext = _viewModel;
24+
}
25+
if (!IsInitialized)
26+
{
1727
InitializeComponent();
1828
}
1929
base.OnNavigatedTo(e);

Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ namespace Flow.Launcher.SettingPages.Views;
1111
public partial class SettingsPanePluginStore
1212
{
1313
private SettingsPanePluginStoreViewModel _viewModel = null!;
14+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1415

1516
protected override void OnNavigatedTo(NavigationEventArgs e)
1617
{
17-
if (!IsInitialized)
18+
// Sometimes the navigation is not triggered by button click,
19+
// so we need to reset the page type
20+
_settingViewModel.PageType = typeof(SettingsPanePluginStore);
21+
22+
// If the navigation is not triggered by button click, view model will be null again
23+
if (_viewModel == null)
1824
{
1925
_viewModel = Ioc.Default.GetRequiredService<SettingsPanePluginStoreViewModel>();
2026
DataContext = _viewModel;
27+
}
28+
if (!IsInitialized)
29+
{
2130
InitializeComponent();
2231
}
2332
_viewModel.PropertyChanged += ViewModel_PropertyChanged;

Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ namespace Flow.Launcher.SettingPages.Views;
1111
public partial class SettingsPanePlugins
1212
{
1313
private SettingsPanePluginsViewModel _viewModel = null!;
14+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1415

1516
protected override void OnNavigatedTo(NavigationEventArgs e)
1617
{
17-
if (!IsInitialized)
18+
// Sometimes the navigation is not triggered by button click,
19+
// so we need to reset the page type
20+
_settingViewModel.PageType = typeof(SettingsPanePlugins);
21+
22+
// If the navigation is not triggered by button click, view model will be null again
23+
if (_viewModel == null)
1824
{
1925
_viewModel = Ioc.Default.GetRequiredService<SettingsPanePluginsViewModel>();
2026
DataContext = _viewModel;
27+
}
28+
if (!IsInitialized)
29+
{
2130
InitializeComponent();
2231
}
2332
_viewModel.PropertyChanged += ViewModel_PropertyChanged;

Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
using System.Windows.Navigation;
22
using CommunityToolkit.Mvvm.DependencyInjection;
33
using Flow.Launcher.SettingPages.ViewModels;
4+
using Flow.Launcher.ViewModel;
45

56
namespace Flow.Launcher.SettingPages.Views;
67

78
public partial class SettingsPaneProxy
89
{
910
private SettingsPaneProxyViewModel _viewModel = null!;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1012

1113
protected override void OnNavigatedTo(NavigationEventArgs e)
1214
{
13-
if (!IsInitialized)
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneProxy);
18+
19+
// If the navigation is not triggered by button click, view model will be null again
20+
if (_viewModel == null)
1421
{
1522
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneProxyViewModel>();
1623
DataContext = _viewModel;
24+
}
25+
if (!IsInitialized)
26+
{
1727
InitializeComponent();
1828
}
1929
base.OnNavigatedTo(e);

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
using System.Windows.Navigation;
22
using CommunityToolkit.Mvvm.DependencyInjection;
33
using Flow.Launcher.SettingPages.ViewModels;
4+
using Flow.Launcher.ViewModel;
45

56
namespace Flow.Launcher.SettingPages.Views;
67

78
public partial class SettingsPaneTheme
89
{
910
private SettingsPaneThemeViewModel _viewModel = null!;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1012

1113
protected override void OnNavigatedTo(NavigationEventArgs e)
1214
{
13-
if (!IsInitialized)
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneTheme);
18+
19+
// If the navigation is not triggered by button click, view model will be null again
20+
if (_viewModel == null)
1421
{
1522
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneThemeViewModel>();
1623
DataContext = _viewModel;
24+
}
25+
if (!IsInitialized)
26+
{
1727
InitializeComponent();
1828
}
1929
base.OnNavigatedTo(e);

0 commit comments

Comments
 (0)