Fix component initialization issue

This commit is contained in:
Jack251970 2025-05-15 19:36:45 +08:00
parent 57dccce1bf
commit 1a67c8906b
12 changed files with 48 additions and 0 deletions

View file

@ -14,10 +14,14 @@ namespace Flow.Launcher.Resources.Pages
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<Settings>();
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -16,10 +16,14 @@ namespace Flow.Launcher.Resources.Pages
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<Settings>();
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -12,10 +12,14 @@ namespace Flow.Launcher.Resources.Pages
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<Settings>();
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -12,10 +12,14 @@ namespace Flow.Launcher.Resources.Pages
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<Settings>();
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -15,10 +15,14 @@ namespace Flow.Launcher.Resources.Pages
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<Settings>();
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -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<SettingsPaneAboutViewModel>();
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -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<SettingsPaneGeneralViewModel>();
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -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<SettingsPaneHotkeyViewModel>();
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -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<SettingsPanePluginStoreViewModel>();
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
_viewModel.PropertyChanged += ViewModel_PropertyChanged;

View file

@ -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<SettingsPanePluginsViewModel>();
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
_viewModel.PropertyChanged += ViewModel_PropertyChanged;

View file

@ -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<SettingsPaneProxyViewModel>();
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,

View file

@ -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<SettingsPaneThemeViewModel>();
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
// Sometimes the navigation is not triggered by button click,