zoukankan      html  css  js  c++  java
  • 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" />
                    <!-- 传递参数是,如传递多个参数时,许将 & 转义为 &amp; -->
                    <appnavigation:UriMapping Uri="TestParam/{value1}/{value2}" MappedUri="/TestPageParam.xaml?id={value1}&amp;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;
  • 相关阅读:
    js判断值是否为数字
    人脸识别 python调用face++ 功能测试
    【转载】Cesium基础使用介绍
    数据分析R&Python-Rpy2包环境配置
    VR/AR软件—Mirra测试(截至2017/11/13),使AR/VR创作更加便捷
    Cesium左右立体视觉续篇——遗留问题(渲染错误)以及临时替代方案
    在CesiumVR基础上实现3D左右立体视觉
    关于css样式的选择问题
    圣杯布局和双飞翼布局
    冒泡排序法
  • 原文地址:https://www.cnblogs.com/my-tzc/p/3500868.html
Copyright © 2011-2022 走看看