《PRISM 4.0 TRAINING KIT Hands-On LabView-Based Navigation》由会员分享,可在线阅读,更多相关《PRISM 4.0 TRAINING KIT Hands-On LabView-Based Navigation(33页珍藏版)》请在金锄头文库上搜索。
1、PRISM 4.0 TRAINING KITHands-On LabView-Based Navigation Lab version:1.0.0 Last updated:10/17/2019ContentsOVERVIEW3EXERCISE 1 IMPLEMENTING A BASIC VIEW-BASED NAVIGATION SCENARIO4Task 1 Adding the Code to Perform View-Based Navigation4Task 2 Configuring Your Application6Verification6EXERCISE 2 - PASSI
2、NG PARAMETERS DURING NAVIGATION9Task 1 Creating the query string to pass parameters to a target view9Task 2 Receiving the parameters in the target view11Verification12EXERCISE 3 CONFIRMING AND CANCELLING NAVIGATION16Task 1 Handling Navigation Confirmation16Task 2 Setting up the Views interaction beh
3、avior18EXERCISE 4 - USING THE NAVIGATION JOURNAL21Task 1 Adding the back and forward buttons21Task 2 - Using the CanGoBack and CanGoForward27OverviewAs the user interacts with a rich client application, its user interface (UI) will be continuously updated to reflect the current task and data that th
4、e user is working on. The UI may undergo considerable changes over time as the user interacts with and completes various tasks within the application. The process by which the application coordinates these UI changes is often referred to as navigation.UI updates can be accomplished by adding or remo
5、ving elements from the applications visual tree, or by applying state changes to existing elements within the visual tree. WPF and Silverlight are very flexible platforms, and it is often possible to implement a particular navigation scenario using either of these two approaches. However, the approa
6、ch that will be most appropriate for your application depends on multiple factors.Prism differentiates between the two styles of navigation: Navigation accomplished via state changes to existing controls in the visual tree is referred to as state-based navigation. Navigation accomplished via the add
7、ition or removal of elements from the visual tree is referred to as view-based navigation. Prism provides guidance on implementing both styles of navigation, focusing on the case where the application is using the Model-View-ViewModel (MVVM) pattern to separate the UI (encapsulated in the view) from
8、 the presentation logic and data (encapsulated in the view model). This Hands-On Lab will focus on explain the view-based navigation which make use of the Prism API.Exercise 1 Implementing a Basic View-Based Navigation ScenarioTask 1 Adding the Code to Perform View-Based NavigationIn this task, you
9、will create some views, which will contain a button with navigation logic.1. Open the View-BasedNavigation.sln solution, located at the NavigationExercise 1Begin folder of this Training Kit.2. In ModuleA, add a UserControl named ModuleANavigationItemView inside the Views folder.3. Add a button to na
10、vigate to ModuleAView view, as shown in the following code.XAMLGo to ModuleAView4. In the code behind for ModuleANavigationItemView, add the following using statements.C#using System.ComponentModel.Composition;using Microsoft.Practices.Prism.Regions;using Infrastructure;5. Decorate the ModuleANaviga
11、tionItemView class with the Export attribute, as shown in the following code.C#Exportpublic partial class ModuleANavigationItemView : UserControl.6. Add the following code in the body of the class.C#private static Uri moduleAViewUri = new Uri(ViewNames.ModuleAView, UriKind.Relative);Importpublic IRe
12、gionManager regionManager;7. In the handler for the Buttons click event, add the following code. The Region.RequestNavigate method is responsible for navigating into a view. The RegionManager.RequestNavigate method calls RequestNavigate in the specified region.C#private void Button_Click(object send
13、er, RoutedEventArgs e) regionManager.RequestNavigate(RegionNames.MainRegion, moduleAViewUri);8. In ModuleB, add a new UserControl named ModuleBNavigationItemView inside the Views folder.9. Add a button to navigate to ModuleBViewXAMLGo to ModuleBView10. In the code behind for ModuleBNavigationItemVie
14、w, repeat the same procedures youve done in steps 4-7, but for ModuleBView. The resulting code should look like this.C#using System.Windows.Controls;using System.ComponentModel.Composition;using Microsoft.Practices.Prism.Regions;using Infrastructure;using System;using System.Windows;namespace Module
15、B.Views Export public partial class ModuleBNavigationItemView : UserControl private static Uri moduleBViewUri = new Uri(ViewNames.ModuleBView, UriKind.Relative); Import public IRegionManager regionManager; public ModuleBNavigationItemView() InitializeComponent(); private void Button_Click(object sender, RoutedEven