原文:windows phone 页面导航(6)

页面导航的例子我们使用的是两个页面,从第一个页面(MainPage)导航到第二个页面(SecondPage),然后可以从第二个页面导航到第一个页面 ,使用的os 7.1;

页面导航没有引入新的命名空间使用的到属性是派生于PhoneApplicationPage类;

MainPage.xaml 文件中用到的代码为:

 <Grid x:Name="ContentPanel" Grid.Row="" Margin="12,0,12,0"></Grid>        <TextBlock x:Name="Navigation" Text="导航到第二个页面" Grid.Row="" VerticalAlignment="Center" HorizontalAlignment="Center" ManipulationStarted="Navigation_ManipulationStarted"></TextBlock>    </Grid>

隐藏文件代码为:

//textblock的导航时间
        private void Navigation_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            //为什么一定是相对的--知识点①
            this.NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

            e.Complete();
            e.Handled = true;
        }

        protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
        {
            //知识点②
            SolidColorBrush scb=new SolidColorBrush ();
            //知识点③
            Color color = new Color();
            color.A = (byte);
            color.R = (byte);
            color.G = (byte);
            color.B = (byte);
            scb.Color = color;

            ContentPanel.Background = scb;
            base.OnManipulationStarted(e);
        }

隐藏文件的代码是在默认代码的基础上加上以上两个方法,实现的效果是当点击(触摸)非名为Navigation的TextBlock元素时,ContenPanel就会改变为设置好的固定颜色,MainPage效果图:

知识点①:this.NavigationService.Navigate() 是页面导航的核心方法参数是URI类型的对象,所以要New该类,并且实例化URI的时候SecondPage.xaml前有斜线,第二个参数表明    此URI是相对于SecondPage.xaml,绝对的URI是指完整引用某个资源如: http://www.sensengo.com/Index.html  相对URI取决于前面定义的基 URI(例如:/Index.html)

    URI的构造函数有一个包含了基URI和相对URI字符串:

Uri(Uri, String)

根据指定的基 URI 和相对 URI 字符串,初始化 Uri 类的新实例

     实例:

Uri baseUri = new Uri("http://www.contoso.com");      Uri myUri = new Uri(baseUri, "catalog/shownew.htm");

     所以URI实例构成了绝对URI,myUri.ToString()字符串是为:http://www.contoso.com/catalog/shownew.htm

  知识点②:SolidColorBrush类是绘制纯色区域,SolidColorBrush的另一种构造方法为:SolidColorBrush(Color),所以以上代码也可以这样实现:   
ContenPane.Backgroud= new solidColorBrush(    Color.FromArgb(,(byte)135,(byte)25,(byte)15)); 

  知识点③Color这里就是SolidColorBrush的属性color设置颜色,color类描绘的就是一个ARGB颜色,在形成图像中的每个像素的颜色表示为一个 32 位数:分别用 8 位表示 Alpha、红色、绿色和蓝色 (ARGB)。 这四个分量的值都是 0 到 255,其中 0 表示没有亮度,255 表示最大亮度。 alpha 分量指定颜色的透明度:0 表示完全透明,255 表示完全不透明。 要确定颜色的 alpha、红色、绿色或蓝色成分

SecondPage.xaml 文件主要代码:

 <Grid x:Name="ContentPanel" Grid.Row="" Margin="12,0,12,0"></Grid>        <TextBlock x:Name="Navigation" Text="导航到第-个页面" Grid.Row="" VerticalAlignment="Center" HorizontalAlignment="Center" ManipulationStarted="Navigation_ManipulationStarted"></TextBlock>    </Grid>

隐藏文件添加的两个方法代码:

 //textblock的导航时间
        private void Navigation_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            //两个方式实现的效果一样,但是原理不同--知识点④
            this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            //this.NavigationService.GoBack();
            e.Complete();
            e.Handled = true;
        }

        protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
        {
            //纯色
            SolidColorBrush scb = new SolidColorBrush();
            //alpha
            Color color = new Color();
            color.A = (byte);
            color.R = (byte);
            color.G = (byte);
            color.B = (byte);
            scb.Color = color;

            ContentPanel.Background = scb;
            base.OnManipulationStarted(e);
        }

知识点④:在这里因为只有两个页面,返回到上一个页面的效果一样,但是原理不同,this.NavigationService.Navigate是实现一个新的URI实例,this.NavigationService.GoBack()则是后退到历史记录中的最新页面,如果没有历史记录页面则退出程序;

 知识点⑤ :墓碑化:因为windows phone手机不支持第三方程序后台,所以提供了另一种方法Tomstone,简单的讲就是在程序A还在运行的情况下,突然其他程序B,此时系统会暂时关闭程序A的线程,并暂存其状态;当程序B使用完毕,程序A线程会重新启动,恢复程序A之前的状态;本节的页面导航就是墓碑化的例子

小结:导航的核心一句话就是:this.NavigationService.Navigate()和返回上一个页面this.NavigationService.GoBack(),简单了解墓碑化;发现一个方  法也可以导航到其他页面如下:

  Uri uri = new Uri("/SecondPage.xaml", UriKind.Relative);            this.NavigationService.Source = uri;

windows phone 页面导航(6)的更多相关文章

  1. Windows Phone 8.1 新特性 - 页面导航

    本篇介绍一下Windows Phone 8.1 中页面导航的实现方式. 大家对Windows Phone 8 中页面导航的实现一定不陌生,我们使用 NavigationService 来实现.具体写法 ...

  2. 与众不同 windows phone (27) - Feature(特性)之搜索的可扩展性, 程序的生命周期和页面的生命周期, 页面导航, 系统状态栏

    原文:与众不同 windows phone (27) - Feature(特性)之搜索的可扩展性, 程序的生命周期和页面的生命周期, 页面导航, 系统状态栏 [索引页][源码下载] 与众不同 wind ...

  3. windows phone8.1:页面导航详解

    小梦给大家带来windows phone 8.1应用开发实战教程,分享自己学习,开发过程中的经验和技巧. 今天给大家分享windows phone 8.1页面导航相关知识.涉及知识点如下: 页面一导航 ...

  4. WinPhone学习笔记(一)——页面导航与页面相关

    最近学一下Windows Phone(接下来简称“WinPhone”)的开发,在很久很久前稍探究一下WinPhone中对一些传感器的开发,那么现在就从头来学学WinPhone的开发.先从WinPhon ...

  5. 【Win10】页面导航的实现

    注:本文基于 Windows 10 10240 及其 SDK 编写,若以后有变化,请以新版本为准. 页面导航我们是再熟悉不过了,浏览器.手机 App 大多都使用这种方式来展示内容.在 Windows ...

  6. wp8.1 Study1: 页面导航&页面间值传递

    摘要:wp8.1与wp8中很多API是不一样了,wp8.1把以前wp7.x时的api去掉了,更多与win8.1的API相似.比如以下的页面导航和页面之间的值传递 1.页面导航 利用Frame.Navi ...

  7. windows phone 页面传值(7)

    原文:windows phone 页面传值(7) 在windows phone 中微软为我们提供了页面间传递参数的解决方案,下面就为大家介绍使用方法,页面传值的案例中我们建立两个页面,一个是MainP ...

  8. Win10系列:JavaScript页面导航

    页面导航是在开发应用的过程中使用频率较高的技术,其中比较常用的导航方式有多页导航和页内导航,采用多页导航方式的应用程序包含一系列的页面,在一个页面中加入另一个页面的链接地址后,单击链接将跳转到指定页面 ...

  9. wp8.1 页面返回 页面导航

    public The_second() public second() { this.InitializeComponent(); Frame frame = Window.Current.Conte ...

随机推荐

  1. delphi 怎么将一个文件流转换成字符串(String到流,String到文件,相互转化)

    //from   http://kingron.myetang.com/zsfunc0d.htm (*//   标题:充分利用pascal字符串类型   说明:和PChar不同,string可以保存# ...

  2. HDU 4857 (反向拓扑排序 + 优先队列)

    题意:有N个人,M个优先级a,b表示a优先于b.而且每一个人有个编号的优先级.输出顺序. 思路来自:与PKU3687一样 在主要的拓扑排序的基础上又添加了一个要求:编号最小的节点要尽量排在前面:在满足 ...

  3. Android 系统搜索框(有浏览记录)

    实现Android 系统搜索框(有浏览记录),先看下效果: 一.配置搜索描述文件  要在res中的xml文件加创建sreachable.xml,内容如下: <?xml version=" ...

  4. POJ 1862 &amp; ZOJ 1543 Stripies(贪心 | 优先队列)

    题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  5. Android监听外部存储设备的状态(SD卡、U盘等等)

    近期在项目中须要对外部存储设备的状态进行监听,所以整理了此笔记,以便日后查看. 外部存储设备的状态变化时发出的广播 对照不同状态下的广播 1. 插入外部SD卡时: 2. 移除外部SD卡时: 3. 连接 ...

  6. Leetcode-Database-176-Second Highest Salary-Easy(转)

    leetcode地址:https://oj.leetcode.com/problems/second-highest-salary/ 这个问题很有趣,是要求我们写个sql来查询Employee表里第二 ...

  7. hdu 1007 最近点对问题(Splay解法)

    为什么要写这个题..经典啊,当然,别以为我用分治做的,不过主要思想还是那神奇的六个点共存(一个h*2h的矩形中最多能放下多少个点使得两两距离不超过h) 其实我是在这里看到的 http://commun ...

  8. R语言数据框行转列实例

    目的:须要把数据框的行列进行转置 方法: # 原始数据框 > hrl_jd_mon     年份 一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月 1 2010年 51 ...

  9. fragment Trying to instantiate a class com.example.testhuanxindemo.MyFragment that is not a Fragmen

    在使用fragment的时候,先创建了一个fragment,然后为他创建布局,并在oncreateview中返回载入该视图的后返回的view,在activity的布局文件里,使用xml布局,用frag ...

  10. HOG算子

    原地址:http://blog.csdn.net/chlele0105/article/details/11991533 梯度直方图特征(HOG) 是一种对图像局部重叠区域的密集型描述符,它通过计算局 ...