1.主要的知识点:
NavigationService.navigate方法
实现步骤:
1.拖动添加工具箱中的button按钮到手机界面上,点中button按钮,右边的button标签背景色变为灰色,修改Content值为页面跳转
2.双击页面跳转按钮,进入代码编辑区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace changePage
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
}
//点击页面跳转按钮触发的方法,跳转到Welcome.xaml页面
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Welcome.xaml", UriKind.Relative));
}
//页面跳转时触发的方法,让用户决定是否跳转页面
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
if (MessageBox.Show("确定要跳到下个页面吗?", "警告提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
{
e.Cancel = true;
}
}
}
}
3.创建跳转后的页面
4.新建页面
5.添加一个TextBlock,同样的修改里面的值
6.点击运行
运行效果: