这个例子是说明导航中传递参数,类似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. 生成uui

    1.安装uuid包 go get github.com/google/uuid 2.目录结构 3.uuid.go package uuid import ( "github.com/goog ...

  2. java_day23~24

    Java基础 GUI编程 核心技术:Swing.AWT 现在GUI并不流行 因为其界面不美观.需要依赖jre环境 Swing public class Demo1 { //init();初始化 pub ...

  3. 基本的dns命令

    打开cmd的方式 win+r 键 输入cmd       管理员方式运行    打开桌面  命令提示符 盘符切换 直接输入要切换的盘 查看当前目录下所有文件   dir 切换目录  cd  /d 跨盘 ...

  4. ArchKeeper (开篇):架构守护平台的问题与理念

    作者:京东科技 倪新明 在敏捷开发环境下,系统通过迭代增量的交付价值,系统架构也是如此.团队不可能在项目之初就建立完美的系统架构,系统架构应该随着系统迭代不断演进.架构演进和架构腐化是看待架构的不同视 ...

  5. 浅谈云原生基础入坑与docker 搭建redis-cluster集群

    浅谈云原生基础入坑与docker 搭建redis-cluster集群 开篇来点自己的小感触:自从走上后端开发这条无法回头的互卷道路以后,在视野内可见新的技术在迭代,更新的技术在不断发行.就拿最近的Op ...

  6. 获取了文心一言的内测及与其ChatGPT、GPT-4 对比结果

    百度在3月16日召开了关于文心一言(知识增强大语言模型)的发布会,但是会上并没现场展示demo.如果要测试的文心一言 也要获取邀请码,才能进行测试的. 我这边通过预约得到了邀请码,大概是在3月17日晚 ...

  7. Java中的String类真的不可变吗?java面试常见问题

      其实在Java中,String类被final修饰,主要是为了保证字符串的不可变性,进而保证了它的安全性.那么final到底是怎么保证字符串安全性的呢?接下来就让我们一起来看看吧. 一. final ...

  8. 当transcational遇上synchronized

    工作当中经常会遇到既需要开启事务管理,同时也需要同步保证线程安全的场景. 比如一个方法 @Transactional public synchronized void test(){ // } 不知道 ...

  9. ABAP READ内表新老语法对比

    1.读取内表行新语法 740新语法中,对标READ,提出了新的语法,如下: 1.1.根据字段值查找 "-----------------------------@斌将军----------- ...

  10. VUE3.x之Proxy 我们为什么要使用Proxy

    Object.defineProperty 劫持数据 只是对对象的属性进行劫持 无法监听新增属性和删除属性 需要使用 vue.set, vue.delete 深层对象的劫持需要一次性递归 劫持数组时需 ...