这个例子是说明导航中传递参数,类似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. linux环境变量配置错误后命令无法使用解决方案

    环境变量配置时多复制了一个空格,导致执行source /etc/profile后提示错误,无法编辑和查看文件 解决方案: 查看当前系统变量:echo $PATH 临时修改:export PATH=/u ...

  2. tensorflow2.0+TF-lite 各种报错

    generic_type: type "InterpreterWrapper" is already registered! 原因:tensorflow2.5.0rc0版本太高,降 ...

  3. 关与python面向对象的认识

    面向对象编程 类:从一堆对象中以抽象的方式把相同的特征归类得到. 抽象类 类 实列 子类抽象为父类,子类继承父类特征. 类实例化为实例,实例抽象为类. class Human(object): cen ...

  4. python数据结构转字符串_python2中字符不显示问题_python2_递归

    # encoding:utf-8 def get_str(data): """将python数据转化为肉眼可见的字符串 :param data: str.dict.lis ...

  5. beta冲刺:汇总博客

    这个作业属于哪个课程 <班级的链接> 这个作业要求在哪里 <作业要求的链接> 这个作业的目标 汇总博客 作业正文 .... 其他参考文献 ... 博客 beta冲刺(1/5) ...

  6. Xenomai 再探

    一.Xenomai API 接口使用总结 Alarm-操作: 在使用实时任务过程中,采用看门狗定时器进行延时操作时,会产生实时域到非实时域的上下文切换操作,从而导致实时线程实时性受到影响,具体如下: ...

  7. 使用dataX收获的教训

    首先是安装dataX,安装非常简单,只需下载对应的压缩包即可. 下载地址:https://github.com/alibaba/DataX 首先我出现的第一个错误:命令提示符界面出现出现乱码. 解决方 ...

  8. Comic Life - 超棒的漫画制作工具,拥有多种动画模版,创作属于自己的漫画

    Comic Life是一个照片编辑器,能够添加各种效果,并基于它们创建漫画.该工具包包括各种各样的模板,可以很容易地将照片放置在工作表上,还有大量各种形状的标注.除了拼贴画上的标注之外,您还可以添加带 ...

  9. MarkdownStudy02DOS窗口

    打开dos窗口 开始里面win系统 win+r,输入cmd 在任意文件下,按住shift+鼠标右键点击,在此处打开PowerShell窗口 资源管理器的地址栏前面加上cmd路径 管理员身份运行 常用的 ...

  10. 19.3 对FAT的支持(harib16c)

    19.3 对FAT的支持(harib16c) 问题:可以正确显示文件开头的512字节的内容,但大于512字节的部分不能正确显示(可能会显示其他文件). 问题本质:磁盘可能将大于512字节的文件离散的保 ...