这个例子是说明导航中传递参数,类似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. 简介及spring mvc初体验

    一.C\S和B\S C/S C/S 是 Client/Server 的简写,简称客户端/服务器模式.例如 QQ 是客户端和服务器模式,首先安装一个客户端到个人电脑,然后登入到腾讯服务器. 缺点:更新不 ...

  2. 本地项目导入svn托管

  3. Windows10远程桌面连接CentOS7图形化桌面

    Step1:在Centos7上检查是否安装了epel库 执行命令:rpm -qa|grep epel 示例: [root@master ~]# rpm -qa|grep epel[root@maste ...

  4. idea远程仓库无法更新导致的各种错误,jar包无法下载

    直接把下面的配置替换成settings.xml中的内容 <?xml version="1.0" encoding="UTF-8"?> <set ...

  5. Windows10电源选项:睡眠、休眠、启用快速启动

    参考链接: http://www.dnpz.net/diannaozhishi/2223.html http://www.cfan.com.cn/2018/0118/130151.shtml 在介绍w ...

  6. 内网jenkins跨版本升级

    概要: 原来使用的jenkins版本为1.6,现在需要升级为最新版2.3.6 由于在内网,不能使用jenkins自带的在线升级工具 升级思路: 由于版本跨度太大,直接copy jenkins目录,启动 ...

  7. token解决cookie的弊端

    token解决cookie的弊端 目录 token解决cookie的弊端 cookie的弊端 token解决弊端一 什么是token和JWT JWT的构成 token工作流程 token解决弊端二 C ...

  8. 推荐一套轻量级的开源图床系统:Light Fast Picture

    如果您跟我一样平时有些博客的习惯,那么图片存储是否有困扰过你呢?今天就给大家推荐一款不错的开源图床系统:Light Fast Picture 它是一个基于koa + vue3.x + typescri ...

  9. Python相关练习说明

    Python练习情况说明 1.练习了在文件中进行统计的相关方法,基本操作其实差不多,步骤基本如下: # 1.打开相关文件,然后利用for循环进行按行读取的操作 # 2.读取的过程中,将读取到的数据加以 ...

  10. 10.4 提高叠加处理速度(2) (harib07d)

    ps:能力有限,若有错误及纰漏欢迎指正.交流 sheet_refreshsub void sheet_refreshsub(struct SHTCTL *ctl, int vx0, int vy0, ...