windows phone URI映射
UriMapping用于在一个较短的URI和你项目中的xaml页的完整路径定义一个映射(别名)。通过使用别名URI,开发者可以在不改变导航代码的情况下来改变一个项目的内部结构。该机制还提供了一个简单的方法以参数在页面之间传递数据,并可以导航到使用参数动态创建的页面。
一、代码映射URI
主要操作时对app.xaml.cs中对RootFrame的属性UriMapper进行赋值。
在app.xaml.cs中添加方法
/// <summary>
/// 创建UriMapping对象
/// </summary>
/// <param name="uri">请求的uri</param>
/// <param name="mappeduri">导航到的uri</param>
/// <returns></returns>
public UriMapping CreateUriMapping(string uri, string mappeduri)
{
return new UriMapping() {
MappedUri=new Uri(mappeduri,UriKind.Relative),
Uri=new Uri(uri,UriKind.Relative)
};
}
并在InitializePhoneApplication()方法初始化后对RootFrame的UriMapper属性赋值
UriMapper mapper = new UriMapper();
//简单的映射
mapper.UriMappings.Add(CreateUriMapping("Test", "/TestPage.xaml"));
//传递参数
mapper.UriMappings.Add(CreateUriMapping("TestParam/{value1}/{value2}", "/TestPageParam.xaml?id={value1}&name={value2}"));
//导航到使用参数动态创建的页面 NavigationService.Navigate(new Uri("Test1",UriKind.Relative)) 访问TestPage1.xaml
mapper.UriMappings.Add(CreateUriMapping("Test{num}", "/TestPage{num}.xaml"));
RootFrame.UriMapper = new UriMapper();
RootFrame.UriMapper = mapper;
二、使用XAML映射URI
首先要添加命名空间
xmlns:appnavigation="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"
在<Application.Resources>中添加如下代码
<appnavigation:UriMapper x:Key="UriMapper">
<appnavigation:UriMapper.UriMappings>
<appnavigation:UriMapping Uri="Test" MappedUri="/TestPage.xaml" />
<!-- 传递参数是,如传递多个参数时,许将 & 转义为 & -->
<appnavigation:UriMapping Uri="TestParam/{value1}/{value2}" MappedUri="/TestPageParam.xaml?id={value1}&name={value2}"/>
<appnavigation:UriMapping Uri="Test{num}" MappedUri="/TestPage{num}xaml"/>
</appnavigation:UriMapper.UriMappings>
</appnavigation:UriMapper>
最后在app的构造函数中对RootFrame的UriMapper属性赋值,InitializePhoneApplication()方法后
RootFrame.UriMapper = Resources["UriMapper"] as UriMapper;
windows phone URI映射的更多相关文章
- Windows Phone开发(17):URI映射
原文:Windows Phone开发(17):URI映射 前面在讲述导航的知识,也讲了控件,也讲了资源,样式,模板,相信大家对UI部分的内容应该有了很直观的认识了.那么今天讲什么呢?不知道大家在练习导 ...
- 关于WIndows内核自映射方案的通俗解释
在一次操作系统课程上听老师说了这么一个有意思的东西,windows的自映射方案居然达到了把4K的页目录的线性地址“藏”在4M页表里的效果,感觉甚是奇特,于是乎就想着说怎么去算.光会算之后仍旧不满足,我 ...
- windows tcp端口映射或端口转发
windows tcp端口映射或端口转发 windows内部有一个叫netsh的玩意,可以把tcp端口进行映射或转发,可惜不支持udp.举个例子:一台windows有一个80端口,对外可以访问.另有一 ...
- 网站开发进阶(三)Windows NAT端口映射
Windows NAT端口映射 由于有需求进行端口映射,又不想装乱七八糟的软件,Windows本身自带的路由远程访问配置太麻烦,还要两块网卡,坑爹啊. 其实Windows本身命令行支持配置端口映射,条 ...
- windows下端口映射(端口转发)
windows下端口映射(端口转发) 转载: https://blog.csdn.net/i1j2k3/article/details/70228043 本文是对网文的归纳整理,算不上原创,摸索过程亲 ...
- UAP开发错误之The given System.Uri cannot be converted into a Windows.Foundation.Uri(windows phone背景更换)
今天博主在开发一款windows phone应用时,希望实现app背景的更换,思路很简单.使用ApplicationDataContainer容器存储我的图片路径,每次载入应用时读取这个路径以决定我用 ...
- Windows 将FTP 映射到本地文件夹 --简化操作
转载自yutiantongbu Windows 将FTP 映射到本地文件夹 --简化操作 1.右键我的电脑,选择映射网络驱动器 2.选择"连接到可用与存储文档和图片的网站" 3.接 ...
- DirectX11 With Windows SDK--23 立方体映射:动态天空盒的实现
前言 上一章的静态天空盒已经可以满足绝大部分日常使用了.但对于自带反射/折射属性的物体来说,它需要依赖天空盒进行绘制,但静态天空盒并不会记录周边的物体,更不用说正在其周围运动的物体了.因此我们需要在运 ...
- DirectX11 With Windows SDK--22 立方体映射:静态天空盒的读取与实现
前言 这一章我们主要学习由6个纹理所构成的立方体映射,以及用它来实现一个静态天空盒. 但是在此之前先要消除两个误区: 认为这一章的天空盒就是简单的在一个超大立方体的六个面内部贴上天空盒纹理: 认为天空 ...
随机推荐
- Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子
Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子 procedure TForm1.Button1Click(Sender: TObject); ...
- iOS开发——动画篇Swift篇&动画效果的实现
Swift - 动画效果的实现 在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...
- 最新cocoapods安装流程,安装过程中遇到的问题及解决方法
最近重新安装了一次cocoapods,参考的安装流程:http://blog.csdn.net/showhilllee/article/details/38398119/ 但是现在的cocoapods ...
- 使用hibernate自动创建Mysql表失败原因
1.使用 schemaExport(hibernate5.2.3)创建Mysql表 @Test public void testSchemaExport() { ServiceRegistry ser ...
- [转]一步步教你如何在 Visual Studio 2013 上使用 Github
介绍 我承认越是能将事情变简单的工具我越会更多地使用它.尽管我已经知道了足够的命令来使用Github,但我宁愿它被集成到IDE中.在本教程中,我会告诉你使用Visual Studio 2013如何实现 ...
- dem30下载地址
http://www.gscloud.cn/listdata/listdata_new.shtml?from=&productId=311#Wzg4LFswLDEwLDEsMF0sW10sW1 ...
- Asp.net封装js的类
using System; using System.Collections.Generic; using System.Text; using System.Web; using System.We ...
- [改善Java代码]在equals中使用getClass进行类型判断
建议47: 在equals中使用getClass进行类型判断 本节我们继续讨论覆写equals的问题.这次我们编写一个员工Employee类继承Person类,这很正常,员工也是人嘛,而且在JEE中J ...
- 神奇的CSS3选择器
话说园子里也混迹多年了,但是基本没写过blog,写点基础的,那就从css3选择器开始吧. Css3选择器 先说下,为什么提倡使用选择器. 使用选择器可以将样式与元素直接绑定起来,在样式表中什么样式与什 ...
- 关于蓝牙设备与ios连接后,自动打开一个app
How to launch an iphone app when an external accessory is either paired over BT or plugged into dock ...