In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "WPF framework Prism navigation Navigation how to use", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in-depth, together to study and learn "WPF framework Prism navigation Navigation how to use" it!
Working with scen
In common business scenarios, page switching is essential, and Prism can use the Navigation feature for page navigation. There are various uses in different scenarios, such as switching page validation, passing parameters, returning to the previous page, returning to the next page, and so on.
The basic conditions of navigation
1. Register the display area
two。 Register the navigation page
1. Register for navigation
Register the view type or add an alias. If you specify an alias, the name defaults to the name of the type in it.
Public class ModuleAModule: IModule {public void OnInitialized (IContainerProvider containerProvider) {} public void RegisterTypes (IContainerRegistry containerRegistry) {/ / add alias "CustomName" containerRegistry.RegisterForNavigation ("CustomName"); / / default name "ViewB" containerRegistry.RegisterForNavigation ();}}
When registering, specify ViewModel or add an alias.
Public class ModuleAModule: IModule {public void OnInitialized (IContainerProvider containerProvider) {} public void RegisterTypes (IContainerRegistry containerRegistry) {/ / specify ViewModel containerRegistry.RegisterForNavigation (); / / specify ViewModel and add alias containerRegistry.RegisterForNavigation ("CustomName");}} 2. Use Navigation
As mentioned in the previous section, we can use the IRegionManager interface for Region registration, management, navigation, etc., so we can now use this interface to implement navigation functions, as shown below:
IRegionManager regionManager =... ; regionManager.RequestNavigate ("RegionName", "ViewName")
Note that we called the RequestNavigate method of the IRegionManager interface and passed two parameters:
RegionName: this parameter is the name of the registered region
ViewName: this parameter is actually the navigation page we registered above, the string type, which corresponds to the nameof of our registration page
3. Navigation with parameters
Just as we want to pass some parameters before the navigation page, we can use NavigationParameters, as follows:
Var param = new NavigationParameters (); param.Add ("Parameter", param); _ regionManger.RequestNavigate ("RegionName", "ViewName", param); / / similar URL address pass parameter _ regionManger.RequestNavigate ("RegionName", "ViewName?id=1&Name=xiaoming"); question?
How do we control the opening process when we use navigation to register a view for a specified area? So, we're going to explain it next.
INavigationAware interface.
INavigationAware
The interface contains three methods, each of which contains the context of the current navigation, as shown below:
Public void OnNavigatedTo (NavigationContext navigationContext) {} public bool IsNavigationTarget (NavigationContext navigationContext) {return true;} public void OnNavigatedFrom (NavigationContext navigationContext) {}
OnNavigatedTo: before the navigation is completed, the parameters passed here and the control of actions such as whether navigation is allowed or not.
IsNavigationTarget: called to determine whether this instance can handle navigation requests. Otherwise, create a new instance
OnNavigatedFrom: this method is triggered when navigation leaves the current page, similar to opening An and then B.
INavigationAware execution process
Get navigation request parameters
As described above, navigation allows us to pass parameters for corresponding logical business processing before we complete the navigation. At this point, we can get all the parameters passed in the OnNavigatedTo method through the navigation context. It is as follows:
Public void OnNavigatedTo (NavigationContext navigationContext) {var id = navigationContext.Parameters.GetValue ("id"); var name = navigationContext.Parameters ["Name"] .ToString ();} IConfirmNavigationRequest
This interface inherits from INavigationAware, so it has one more feature: it allows users to intercept navigation requests.
/ / A callback function has been added, which indicates whether to intercept the navigation request void ConfirmNavigationRequest (NavigationContext navigationContext, Action continuationCallback); IConfirmNavigationRequest executes the process
Intercept navigation requests
When you open a new navigation, there may be cases where you need to be confirmed by the user. In this case, the IConfirmNavigationRequest API can meet the requirements, as follows:
Public void ConfirmNavigationRequest (NavigationContext navigationContext, Action continuationCallback) {bool result = true; if (MessageBox.Show ("confirm navigation?", "warm reminder", MessageBoxButton.YesNo) = = MessageBoxResult.No) result = false; / / decide whether to start the navigation continuationCallback (result) by calling back the confirmation result currently returned;} Navigation Journal
Navigation log is actually a management function of the navigation system. Theoretically, we should know the location of our last navigation and the location of the next navigation, including the history of our navigation. So that we can use navigation to control the application flexibly.
IRegionNavigationJournal
The interface includes the following features:
GoBack (): returns to the previous page
CanGoBack: can you return to the previous page?
GoForward (): return to the next page
CanGoForward: can you return to the next page?
1. Example (return to previous page)
When the navigation log contains the history of the previous page, as shown below, D is preceded by a record of ABC, so for D, it can return to the previous page, so CanGoBack is True.
two。 Example (return to the next page)
When the navigation log contains the next history, as shown below, D is followed by a record of E, so for D, it can return to the next page, so CanGoForward is True.
Thank you for reading, the above is the content of "how to use the navigation Navigation in the WPF framework Prism". After the study of this article, I believe you have a deeper understanding of how to use the navigation Navigation in the WPF framework Prism, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.