WinPhone 开发(1)-----在 XAML 页面之间浏览和数据的传递、保留以及恢复
生活随笔
收集整理的這篇文章主要介紹了
WinPhone 开发(1)-----在 XAML 页面之间浏览和数据的传递、保留以及恢复
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用控件HyperlinkButton實現XAML頁面之間的瀏覽,使用方法:設置HyperlinkButton的NavigateUri為"/ProjectName;component/folder/PageName.xaml" ,其中ProjectName、PageName根據實際情況來改變。如果有XAML頁面時建立在一個文件夾里面,那么就要加上文件名字folder。
換而言之,利用HyperlinkButton導航到另一個XAML頁面把NavigateUri設置為"/工程名;component/XAML頁面的相對路徑"。
數據的傳遞:使用QueryString獲取NavigateUri中的鍵值對。
demo:NavigateUri="/Testnavigation;component/Views/Page1.xaml=id=1"
1 private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
2 {
3 string id = "";
4 if (NavigationContext.QueryString.TryGetValue("id", out id))
5 {
6 textBox1.Text = String.Format("Value:{0}", id);
7 }
8 }
數據的保留與恢復:重寫方法
2 // retain the value of the textbox
3 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
4 {
5 phoneAppService.State["myValue"] = textBox1.Text;
6 base.OnNavigatedFrom(e);
7 }
8 // try to get the value which is retained
9 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
10 {
11 object someObject;
12 if (phoneAppService.State.ContainsKey("myValue"))
13 {
14 if (phoneAppService.State.TryGetValue("myValue", out someObject))
15 {
16 textBox1.Text = someObject.ToString();
17 }
18 }
19 base.OnNavigatedTo(e);
20 }
一步一腳印,自己的路自己走
轉載于:https://www.cnblogs.com/crazypig/archive/2012/02/27/2370435.html
總結
以上是生活随笔為你收集整理的WinPhone 开发(1)-----在 XAML 页面之间浏览和数据的传递、保留以及恢复的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 预览文章: c++ primer学习笔记
- 下一篇: As3回调函数的使用方法