首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

PhoneApplicationService 不起作用呢,该如何解决

2013-01-02 
PhoneApplicationService 不起作用呢using Systemusing System.Collections.Genericusing System.Linqu

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 

热点排行