zoukankan      html  css  js  c++  java
  • windows phone 7 基本导航

    一个简单的示例------页面间导航。

      在MainPage.xaml的内容区域(content area)放置一个TextBlock,并对其ManipulationStarted事件注册一个事件处理程序:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margain="12,0,12,0">

      <TextBlock Text="导航到第二个页面"  //TextBlock要显示的文本信息

            HorizontalAlignment="Center"  //水平对齐方式为居中

            VerticalAlingment="Center"   //竖直对齐方式为居中

            Padding="0 34"  //内边距设置

            ManipulationStarted="OnTextBlockManipulationStarted" />

    </Grid>

        在MainPage.xaml.cs中的构造函数后面添加以下代码

      void OnTextBlockManipulationStarted(object sender,ManipulationStartedEventArgs e)

    {

      //Navigate方法的第一个参数是一个Uri类型的对象。第二个参数使用了UriKind.Relative来标明此Uri是相对于MainPage.xaml文件的相对位置。

      this.NavigationService.Navigate(new Uri("/SecondPage.xaml",UriKind.Relative));

      

      e.Complete();

      e.Handled = true;

    }

      代码到此已ok,接下来创建第二个页面

      在Visual Studio的SolutionExplorer上右击项目名,选择Add(新增)和New Item(新建项),选择 Windows Phone Portrait Page(Windows Phone竖直页面),改名为SecondPage

      SecondPage的内容,和第一个页面类似

    <Grid x:Name="ContentPanel" Grid.Row="1" Margain="12,0,12,0">

      <TextBlock Text="返回到第一个页面"  

            HorizontalAlignment="Center" 

            VerticalAlingment="Center"  

            Padding="0 34"  

            ManipulationStarted="OnTextBlockManipulationStarted" />

    </Grid>

      接下来在SecondPage.xaml.cs里创建返回第一个页面的触摸事件

      void OnTextBlockManipulationStarted(object sender,ManipulationStartedEventArgs e)

    {

      this.NavigateService.GoBack();

      e.Complete();

      e.Handled = true;

    }

      提示:要先引入System.Windows.Navigation命名空间

  • 相关阅读:
    HDU 4861 Couple doubi(数论)
    POJ 3233 Matrix Power Series 二分+矩阵乘法
    js原生offsetParent解析
    ADS-B显示终端6.8
    模板
    习题四——数字智力题
    Android ORMLite ForeignCollection关联外部集合
    Android应用程序无法读写USB设备的解决方法
    [学习笔记]批次需求计划-十一大量
    jqury+css实现可弹出伸缩层
  • 原文地址:https://www.cnblogs.com/sparks/p/2517288.html
Copyright © 2011-2022 走看看