读书人

PhoneApplicationService 不起作用呢,

发布时间: 2013-01-02 13:08:44 作者: rapoo

PhoneApplicationService 不起作用呢

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;
using Microsoft.Phone.Shell;
using System.Windows.Navigation;

namespace 墓碑机制
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
}

//当页面成为活动页面时调用
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
//还原文本框1中的数据
if (PhoneApplicationService.Current.State.ContainsKey("文本框1"))
{
textBox1.Text = Convert.ToString(PhoneApplicationService.Current.State["文本框1"]);
}
}


//当页面不再是活动页面时调用,将数据保存到“墓碑”中
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
PhoneApplicationService.Current.State["文本框1"] = textBox1.Text; //保存textbox1中的数据

}
}
}


当我按下后退键再进入这个程序的时候 textbox1 没有还原墓碑数据?为什么呢
[解决办法]
墓碑以后的数据是不会保存在内存里的,需要持久化。
休眠过程才会保存在内存里,也就是你的PhoneApplicationService

读书人网 >Windows Mobile

热点推荐