• 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命名空间

  • 相关阅读:
    修改计算机名并更新sqlserver中存储的服务器名称
    SqlServer递归查询
    CSS实现文本溢出显示省略号
    浏览器缓存
    闭包(匿名函数) php
    github添加ssh认证
    hive内置方法一览
    Redis went away
    慢查询日志分析(mysql)
    慢查询日志(mysql)
  • 原文地址:https://www.cnblogs.com/sparks/p/2517288.html
Copyright © 2020-2023  润新知