这个例子是说明导航中传递参数,类似Asp.net中实现。

例子的模板,是例16中使用regionContext实现过的。在例16中,

<Grid x:Name="LayoutRoot" Background="White" Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> <ListBox x:Name="_listOfPeople" ItemsSource="{Binding People}"/>
<ContentControl Grid.Row="1" Margin="10"
prism:RegionManager.RegionName="PersonDetailsRegion"
prism:RegionManager.RegionContext="{Binding SelectedItem, ElementName=_listOfPeople}"/>
</Grid>

也是绑定到上面的列表项,但是数据是在RegioContext中解析。

本例中,

public PersonListViewModel(IRegionManager regionManager)
{
_regionManager = regionManager; PersonSelectedCommand = new DelegateCommand<Person>(PersonSelected);
CreatePeople();
} private void PersonSelected(Person person)
{
var parameters = new NavigationParameters();
parameters.Add("person", person); if (person != null)
_regionManager.RequestNavigate("PersonDetailsRegion", "PersonDetail", parameters);
}

本例中,导航命令中的使用了参数,而参数是一个字典形式。

到了目标视图中,又解析字典,将数值放到VM中

 1  public class PersonDetailViewModel : BindableBase, INavigationAware
2 {
3 private Person _selectedPerson;
4 public Person SelectedPerson
5 {
6 get { return _selectedPerson; }
7 set { SetProperty(ref _selectedPerson, value); }
8 }
9
10 public PersonDetailViewModel()
11 {
12
13 }
14
15 public void OnNavigatedTo(NavigationContext navigationContext)
16 {
17 var person = navigationContext.Parameters["person"] as Person;
18 if (person != null)
19 SelectedPerson = person;
20 }
21
22 public bool IsNavigationTarget(NavigationContext navigationContext)
23 {
24 var person = navigationContext.Parameters["person"] as Person;
25 if (person != null)
26 return SelectedPerson != null && SelectedPerson.LastName == person.LastName;
27 else
28 return true;
29 }
30
31 public void OnNavigatedFrom(NavigationContext navigationContext)
32 {
33
34 }
35 }

15行就是解析参数包(类似viewbag)并获得数据。

22行在是否创建视图实例上,根据本地数据已经有并且姓名相同的话,采用原有数据,否则创建新实例。

Prism Sample 21-PassingParameters的更多相关文章

  1. Android 主题动态切换框架:Prism

    Prism(棱镜) 是一个全新的 Android 动态主题切换框架,虽然是头一次发布,但它所具备的基础功能已经足够强大了!本文介绍了 Prism 的各种用法,希望对你会有所帮助,你也可以对它进行扩展, ...

  2. [转]Blue Prism Architecture

    本文转自:https://mindmajix.com/blue-prism-architecture Introduction Automation technology is widely bloo ...

  3. Spark 算子

    0.parallelize 1.map 2.mapValues 3.flatMap 4.mapPartitions 5.mapPartitionsWithIndex 6.filter 7.reduce ...

  4. PRISM 4 - RegisterViewWithRegion & Custom Export Attributes

    5down votefavorite   I am using Prism 4 with MEF Extensions and the MVVM pattern. During initializat ...

  5. Basic linux command-with detailed sample

    Here I will list some parameters which people use very ofen, I will attach the output of the command ...

  6. [转]simple sample to create and use widget for nopcommerce

    本文转自:http://badpaybad.info/simple-sample-to-create-and-use-widget-for-nopcommerce Here is very simpl ...

  7. FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

    FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice t ...

  8. [转] Spring MVC sample application for downloading files

    http://www.codejava.net/frameworks/spring/spring-mvc-sample-application-for-downloading-files n this ...

  9. Tomcat8.0.21登录时忘记用户名和密码

    大概是这学期开学没多久吧,4月份的时候,为了学习javaEE,装了Tomcat.过了这么久早就忘记用户名和密码了,所以无法进入Tomcat的管理界面.百度(其实我也很想用google)了一堆,几乎都是 ...

  10. Linux Rootkit Sample && Rootkit Defenser Analysis

    目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...

随机推荐

  1. C/C++ 异常处理机制(例:文件拷贝)

    异常是一种程序控制机制,与函数机制互补. 函数是一种以栈结构展开的上下函数衔接的程序控制系统,异常是另一种控制结构,它可以在出现"意外"时中断当前函数,并以某种机制(类型匹配)回馈 ...

  2. JavaScript 字符串和正则相关的方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Oracle入门- 数据库操作相关脚本

    1. 创建表 1 CREATE TABLE SYS_NOTICE 2 ( 3 GUID CHAR(32) NOT NULL, 4 TITLE VARCHAR2(128) NOT NULL 5 ); 6 ...

  4. 微信小程序-实现微信登录

    业务流程: 1:首先需要一个按钮触发事件 2:调用微信小程序的登录接口wx.login,拿到code 3:调用微信小程序的获取用户信息的接口wx.getUserProfile,拿到用户的个人信息 4: ...

  5. 关于rust cargo下载依赖慢的解决方法(转载)

    网址: https://zhuanlan.zhihu.com/p/74875840?from_voters_page=true win环境基本输入两个命令就好了 $env:http_proxy=&qu ...

  6. vue下拉选择select option el-cascader删除重选值的问题

    select当下拉值多的时候 以及input cascader级联选择一个值后  后面我不想要了 vue  提供了一个关键字  可以帮你全部清空 这个关键字就是:clearable

  7. SpringBoot解决跨域方案

    SpringBoot解决跨域的几种方式 跨域资源共享(CORS):通过修改Http协议header的方式,实现跨域.说的简单点就是,通过设置HTTP的响应头信息,告知浏览器哪些情况在不符合同源策略的条 ...

  8. [SUCTF 2019]EasySQL 1

    这个题目搞了我好久,由于本人基础不扎实,试了好多方法,只发现有三种情况 Nonono.无返回结果和有返回 然后使用了新学习的堆叠注入,得到了数据库名和表名 想要查看Flag表的字段内容也查看不了 这里 ...

  9. 【RSocket】使用 RSocket(二)——四种通信模式实践

    Source Code: https://github.com/joexu01/rsocket-demo 0. 四种通信模式 让我们来简单复习一下 RSocket 的四种通信模式: 即发即忘 - Fi ...

  10. Hive中的高级函数

    高级函数 1.炸裂函数 UDTF 通常是将数组或者集合中或者结构体(涉及到数据类型-------复杂数据类型)中的元素单个输出 特点:接收一行数据,输出一行或多行数据 2.窗口函数/开窗函数 概念:能 ...