资源预览内容
第1页 / 共33页
第2页 / 共33页
第3页 / 共33页
第4页 / 共33页
第5页 / 共33页
第6页 / 共33页
第7页 / 共33页
第8页 / 共33页
第9页 / 共33页
第10页 / 共33页
亲,该文档总共33页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
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 - PASSING 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 behavior18EXERCISE 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 the 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 removing 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 approach 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 addition 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 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 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 navigate 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 ModuleANavigationItemView 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 IRegionManager 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 sender, 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 ModuleBNavigationItemView, 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 ModuleB.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
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号