You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
using System; |
|
using FluentAvalonia.UI.Controls; |
|
using FluentAvalonia.UI.Media.Animation; |
|
using FluentAvalonia.UI.Navigation; |
|
using StabilityMatrix.Avalonia.ViewModels.Base; |
|
|
|
namespace StabilityMatrix.Avalonia.Services; |
|
|
|
public class NavigationService : INavigationService |
|
{ |
|
private Frame? _frame; |
|
|
|
/// <inheritdoc /> |
|
public void SetFrame(Frame frame) |
|
{ |
|
_frame = frame; |
|
} |
|
|
|
/// <inheritdoc /> |
|
public void NavigateTo<TViewModel>(NavigationTransitionInfo? transitionInfo = null) where TViewModel : ViewModelBase |
|
{ |
|
if (_frame is null) |
|
{ |
|
throw new InvalidOperationException("SetFrame was not called before NavigateTo."); |
|
} |
|
|
|
_frame.NavigateToType(typeof(TViewModel), |
|
null, |
|
new FrameNavigationOptions |
|
{ |
|
IsNavigationStackEnabled = true, |
|
TransitionInfoOverride = transitionInfo ?? new SuppressNavigationTransitionInfo() |
|
}); |
|
} |
|
|
|
/// <inheritdoc /> |
|
public void NavigateTo(ViewModelBase viewModel, NavigationTransitionInfo? transitionInfo = null) |
|
{ |
|
if (_frame is null) |
|
{ |
|
throw new InvalidOperationException("SetFrame was not called before NavigateTo."); |
|
} |
|
|
|
_frame.NavigateFromObject(viewModel, |
|
new FrameNavigationOptions |
|
{ |
|
IsNavigationStackEnabled = true, |
|
TransitionInfoOverride = transitionInfo ?? new SuppressNavigationTransitionInfo() |
|
}); |
|
} |
|
}
|
|
|