8、跳转页面,并传参
通过点击事件跳转
//跳转到BlankPage2页面,将参数txt.Text传到这个页面
...Click...
{
this.Frame.Navigate(typeof(BlankPage2),txt.Text);
}
在Page2中找到下面方法,并添加实现代码
protectedasync override void OnNavigatedTo(NavigationEventArgs e)
{
string str = e.Parameter as string;
if (str == null ||string.IsNullOrEmpty(str.Trim()))
{
await newMessageDialog("没有参数").ShowAsync();
}
else
{
txt.Text = str;
}
}
9、弹出一个提示框(WP8.1中无MessageBox)
//要在函数前加关键字async
private async void Click ..{
await new MessageDialog("提示信息").ShowAsync();
}
10、(!!有bug)使用手机返回键"<——"返回
再目标页面手动添加一个方法Windows.Phone.UI.Input.HardwareButtons.BackPressed +=HardwareButtons_BackPressed;
添加后悔自动在外面生成一个名为ardwareButtons_BackPressed的方法
publicBlankPage2()
{
this.InitializeComponent();
Windows.Phone.UI.Input.HardwareButtons.BackPressed +=HardwareButtons_BackPressed;
}
//加上关键字async,并写入返回功能的函数
privateasync void HardwareButtons_BackPressed(object sender,Windows.Phone.UI.Input.BackPressedEventArgs e)
{
//throw newNotImplementedException();
//注释上航代码,写入返回函数
if(this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
else
{
await newMessageDialog("无法返回上一级").ShowAsync();
}
}
11、微软跳转方案BasicPage页面(可直接使用实体键返回前一页面)
1)->添加项目->基础页
2)在BasicPage1页面代码中找到此方法,加入缓存页面数据(跳转页面时数据不会丢失)
publicBasicPage1()
{
this.InitializeComponent();
this.navigationHelper = newNavigationHelper(this);
this.navigationHelper.LoadState +=this.NavigationHelper_LoadState;
this.navigationHelper.SaveState +=this.NavigationHelper_SaveState;
//加入缓存页面数据的功能
this.NavigationCacheMode =Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;
}
应用结束后数据清空