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. 16
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml.cs

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

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

Loading…
Cancel
Save