这个例子是说明导航中传递参数,类似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. K8S二进制单节点部署

    一.常见的k8s部署方式 1.inikube: Minikube是一个工具,可以在本地快速运行一个单节点微型K8s,仅用于学习预览K8s的一些特性使用 部署地址: https://kubernetes ...

  2. oracle数据库常用操作

    1,调整显示格式 col username for a20 col DEFAULT_TABLESPACE for a30 2,查看表空间 select username,default_tablesp ...

  3. Oracle表主键作为外键都用在哪些表查询

    Oracle中,如果设置了外键,删除数据时,必须将外键关联一并删除,但是如果对项目不是很熟悉时,我们无法判断到底都在哪些表中有外键关联,以下提供了一个查询的SQL,可以通过数据库查询,查找到所有的外键 ...

  4. 阿里云CentOS7 下部属nginx+uwsgi+python3+django

    安装依赖包 yum -y groupinstall "Development tools" yum install openssl-devel bzip2-devel expat- ...

  5. loadrunner入门(关联)

    左右边界:提取第一个id web_reg_save_param_ex(                 "ParamName=Id",         "LB=//OK[ ...

  6. bind、call、apply区别

    bind.call.apply都是用来改变函数内部this指向的方法,使用上仅有细微差别 一.代码 function person(p1, p2, p3) { console.log('this: ' ...

  7. axios请求本地文件404

    解决办法:将json文件放在public文件夹下 请求页面的url路径这样写,不能加上../public/这样的路径,直接就是/aa.json

  8. 操作kubernets(k8s)的增删改查

    资源的CRUD: 创建: Service service = client.services().inNamespace(namespace).create(service); 更新: Namespa ...

  9. Linux 里面安装多个jdk,进行切换

    alternatives --config java

  10. 刘勇智:一码通缺陷分析与架构设计方案丨声网开发者创业讲堂 Vol.02

    本文内容源自「声网开发者创业讲堂 Vol.02」的演讲分享,分享讲师为 Thoughtworks 专家级咨询师刘勇智.大家可以点击此链接,观看视频回放以及下载讲师 PPT. 从去年年底到现在,随着疫情 ...