小洪維尼 发表于 2015-5-13 08:39:35

windows phone 7 基本导航

  一个简单的示例------页面间导航。
  
  在MainPage.xaml的内容区域(content area)放置一个TextBlock,并对其ManipulationStarted事件注册一个事件处理程序:
  
  
  
  
  在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的内容,和第一个页面类似
  
  
  
  接下来在SecondPage.xaml.cs里创建返回第一个页面的触摸事件
  void OnTextBlockManipulationStarted(object sender,ManipulationStartedEventArgs e)
  {
  this.NavigateService.GoBack();
  e.Complete();
  e.Handled = true;
  }
  提示:要先引入System.Windows.Navigation命名空间
  
页: [1]
查看完整版本: windows phone 7 基本导航