Prism Sample 21-PassingParameters
这个例子是说明导航中传递参数,类似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的更多相关文章
- Android 主题动态切换框架:Prism
Prism(棱镜) 是一个全新的 Android 动态主题切换框架,虽然是头一次发布,但它所具备的基础功能已经足够强大了!本文介绍了 Prism 的各种用法,希望对你会有所帮助,你也可以对它进行扩展, ...
- [转]Blue Prism Architecture
本文转自:https://mindmajix.com/blue-prism-architecture Introduction Automation technology is widely bloo ...
- Spark 算子
0.parallelize 1.map 2.mapValues 3.flatMap 4.mapPartitions 5.mapPartitionsWithIndex 6.filter 7.reduce ...
- PRISM 4 - RegisterViewWithRegion & Custom Export Attributes
5down votefavorite I am using Prism 4 with MEF Extensions and the MVVM pattern. During initializat ...
- 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 ...
- [转]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 ...
- 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 ...
- [转] Spring MVC sample application for downloading files
http://www.codejava.net/frameworks/spring/spring-mvc-sample-application-for-downloading-files n this ...
- Tomcat8.0.21登录时忘记用户名和密码
大概是这学期开学没多久吧,4月份的时候,为了学习javaEE,装了Tomcat.过了这么久早就忘记用户名和密码了,所以无法进入Tomcat的管理界面.百度(其实我也很想用google)了一堆,几乎都是 ...
- Linux Rootkit Sample && Rootkit Defenser Analysis
目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...
随机推荐
- TensorFlow 的 Graph 模式转换
定义 TensorFlow 图形并将其保存到磁盘上. 使用 TensorFlow 的 tf.Graph() 和 tf.Session() 函数来定义和运行 TensorFlow 图形,并使用 tf.t ...
- OpenStack组件说明
1.版本对应组件 2.Juno版本的核心组件
- Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on
解决错误 Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test ...
- egret 图片跨域
//图片跨域 egret.ImageLoader.crossOrigin = "anonymous";
- nginx配置https详细过程
准备工作 需要先准备好你域名对应的证书和私钥,也就是cert证书和key.我部署是很常见的ng+tomcat双层配置,ng作为前端的代理,所以tomcat就不需要自己处理https,ng作为代理以ht ...
- docker 学习之一 装MySQL 供远程使用 Linux
因为Linux发行版本的问题折腾了好久,尽量使用LTS的版本.其他版本有时候缺的东西太多了,对新手相当不友好. 大概花了几天实在没招了,下了个LTS的版本,再装时正常了.按照官方文档都可以搞定了. 使 ...
- Java笔记第九弹
升级版: 数据安全问题的解决 1.同步代码块 (弊端:降低了运行效率) 格式:(锁--同一把锁) synchronized(任意对象){ 多条语句操作共享数据的代码 } //sellTicket.ja ...
- MySQL学习(十一)B树与B+树了解
参考博客:https://www.cnblogs.com/kismetv/p/11582214.html
- StyleGAN 生成 AI 虚拟人脸,再也不怕侵犯肖像权
目录 什么是 StyleGAN 如何使用 StyleGAN 下载项目 修改项目 MSVC 运行项目 运行结果 什么是 StyleGAN GAN 是机器学习中的生成性对抗网络,目标是合成与真实图像无法区 ...
- MySQL 更新执行的过程
更多内容,前往 IT-BLOG Select语句的执行过程会经过连接器.分析器.优化器.执行器.存储引擎,同样的 Update语句也会同样走一遍 Select语句的执行过程. 但是和 Select ...