Browse Source

Prevent navigation if on same page and initial if loaded

pull/324/head
Ionite 1 year ago
parent
commit
7057d561bd
No known key found for this signature in database
  1. 28
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml.cs

28
StabilityMatrix.Avalonia/Views/SettingsPage.axaml.cs

@ -23,6 +23,8 @@ public partial class SettingsPage : UserControlBase
{ {
private readonly INavigationService<SettingsViewModel> settingsNavigationService; private readonly INavigationService<SettingsViewModel> settingsNavigationService;
private bool hasLoaded;
private SettingsViewModel ViewModel => (SettingsViewModel)DataContext!; private SettingsViewModel ViewModel => (SettingsViewModel)DataContext!;
[DesignOnly(true)] [DesignOnly(true)]
@ -47,16 +49,19 @@ public partial class SettingsPage : UserControlBase
{ {
base.OnLoaded(e); base.OnLoaded(e);
Dispatcher.UIThread.Post( if (!hasLoaded)
() => {
settingsNavigationService.NavigateTo( // Initial load, navigate to first page
ViewModel.SubPages[0], Dispatcher.UIThread.Post(
new BetterSlideNavigationTransition () =>
{ settingsNavigationService.NavigateTo(
Effect = SlideNavigationTransitionEffect.FromBottom ViewModel.SubPages[0],
} new SuppressNavigationTransitionInfo()
) )
); );
hasLoaded = true;
}
} }
private void NavigationService_OnTypedNavigation(object? sender, TypedNavigationEventArgs e) private void NavigationService_OnTypedNavigation(object? sender, TypedNavigationEventArgs e)
@ -81,7 +86,8 @@ public partial class SettingsPage : UserControlBase
BreadcrumbBarItemClickedEventArgs args BreadcrumbBarItemClickedEventArgs args
) )
{ {
if (args.Item is not PageViewModelBase viewModel) // Skip if already on same page
if (args.Item is not PageViewModelBase viewModel || viewModel == ViewModel.CurrentPage)
{ {
return; return;
} }

Loading…
Cancel
Save