1using System.Reflection.Metadata;
4using System.Windows.Navigation;
19 private object _lastParameterUsed;
39 _pageService = pageService;
48 _frame.Navigated += OnNavigated;
55 _frame.Navigated -= OnNavigated;
64 var vmBeforeNavigation = _frame.GetDataContext();
68 navigationAware.OnNavigatedFrom();
74 public bool NavigateTo(
string pageKey,
object parameter =
null,
bool clearNavigation =
false)
76 var pageType = _pageService.GetPageType(pageKey);
78 if (_frame.Content?.GetType() != pageType || (parameter !=
null && !parameter.Equals(_lastParameterUsed)))
80 _frame.Tag = clearNavigation;
81 var page = _pageService.GetPage(pageKey);
82 var navigated = _frame.Navigate(page, parameter);
85 _lastParameterUsed = parameter;
86 var dataContext = _frame.GetDataContext();
89 navigationAware.OnNavigatedFrom();
109 var pageType = _pageService.GetPageType(pageKey);
112 var page = _pageService.GetPage(pageKey);
113 var navigated = _frame.Navigate(page, _lastParameterUsed);
116 var dataContext = _frame.GetDataContext();
119 navigationAware.OnNavigatedFrom();
127 => _frame.CleanNavigation();
129 private void OnNavigated(
object sender, NavigationEventArgs e)
131 if (sender is Frame frame)
133 bool clearNavigation = (bool)frame.Tag;
136 frame.CleanNavigation();
139 var dataContext = frame.GetDataContext();
142 navigationAware.OnNavigatedTo(e.ExtraData);
145 Navigated?.Invoke(sender, dataContext.GetType().FullName);
void Initialize(Frame shellFrame)
Initializes the navigation service with the provided frame.
void CleanNavigation()
Cleans the navigation stack of the frame.
bool ReloadCurrent()
Navigate to the current page again.This can be used to trigger the INavigationAware....
void GoBack()
Goes back to the previous page in the navigation stack if possible.
bool CanGoBack
True if the frame can navigate back, false otherwise.
FrameworkElement CurrentFrameContent
Current FrameworkElement that is displayed in the Frame.Most times this is a page.
NavigationService(IPageService pageService)
Constructor for the NavigationService.
void UnsubscribeNavigation()
Unsubscribes from navigation events and clears the frame reference.
bool NavigateTo< T_VM >(object parameter=null, bool clearNavigation=false)
Navigates to the specified page using its view model type.True on navigation success
object CurrentFrameViewModel
View model used by the CurrentFrameContent
bool NavigateTo(string pageKey, object parameter=null, bool clearNavigation=false)
Navigates to the specified page using its key.True on navigation success
EventHandler< string > Navigated
Interface for a service for handling navigation within the application.
Interface for a service to manage pages in the application.
Interface for objects that need to handle navigation events.