简体   繁体   English

windows 手机 7,帮助返回按钮和页面,保存变量

[英]windows phone 7, help with the back button and pages, saving variables

I am having yet another problem with my application for my phone.我的手机应用程序还有另一个问题。

My problem is the following:我的问题如下:

On one page I have a list of pictures, and a button marked as "favorite."在一个页面上,我有一个图片列表,以及一个标记为“收藏”的按钮。 If you are to favorite the particular image of the row, the border of the image changes colors to signify this.如果您要收藏该行的特定图像,则图像的边框会更改 colors 以表示这一点。

However, whenever I tombstone my application or hit the back button and go back to that very same page, the borders of the images are back to their default color.但是,每当我删除我的应用程序或点击后退按钮并将 go 返回到同一页面时,图像的边框就会恢复为默认颜色。

Now before you ask, I have no idea if this is an isolated memory problem.现在在你问之前,我不知道这是否是一个孤立的 memory 问题。 I have just begun looking into Isolated storage, and it's difficult for me to grasp at the moment.我刚刚开始研究隔离存储,目前我很难掌握。

Maybe this is a saving state problem?也许这是一个节省 state 的问题?

Either way, I would like to have my application remember what the favorites are whenever a user exits the application or tombstones it, or hits the back button, etc.无论哪种方式,我都想让我的应用程序记住每当用户退出应用程序或删除它,或点击后退按钮等时收藏夹是什么。

Could someone please provide a piece of code in order to help with this?有人可以提供一段代码来帮助解决这个问题吗?

You need to save your data because the system is basically killing your app.您需要保存数据,因为系统基本上正在杀死您的应用程序。 So you need in your app.xaml.cs write code to save and read your data in metods:因此,您需要在您的 app.xaml.cs 中编写代码以在方法中保存和读取您的数据

    // Code to execute when the application is launching (eg, from Start)
    // This code will not execute when the application is reactivated
    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
    }

    // Code to execute when the application is activated (brought to foreground)
    // This code will not execute when the application is first launched
    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
    }

    // Code to execute when the application is deactivated (sent to background)
    // This code will not execute when the application is closing
    private void Application_Deactivated(object sender, DeactivatedEventArgs e)
    {
    }

    // Code to execute when the application is closing (eg, user hit Back)
    // This code will not execute when the application is deactivated
    private void Application_Closing(object sender, ClosingEventArgs e)
    {
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM