如何在 windows phone 应用程序关闭并再次打开时保留更改的控件状态

How to retain changed state of controls when windows phone app is closed and opened again

我开发了一个 Windows phone 应用程序,它允许用户将主题更改为 Light 主题,但是当用户关闭应用程序并重新启动应用程序时,它会以默认状态启动即控件再次变黑等

如何在应用程序关闭时保留更改?

您应该保存配置设置,并在加载应用程序时将其应用于主题。在 IsolatedStorageSettings.ApplicationSettings.

中有一个对象可以存储 key/value 对

这是一个 microsoft example,您可以用它来为您的主题设置编写类似的内容。

IsolatedStorageSettings localSettings = IsolatedStorageSettings.ApplicationSettings

//save the theme when user chooses their preference
localSettings.Values["theme"] = "light";

//retrieve the user's preference
string theme = (string)localSettings.Values["theme"];

您可能想要创建一个设置 class 来定义您的设置、声明默认值和检查空值。也有一个 Microsoft 示例:How to create a settings page。然后,您可以使用应用程序生命周期事件在您的应用程序打开时加载您的设置和主题

Use the State property of the PhoneApplicationService class to store transient application state in the Deactivated event handler and to retrieve application state in the Activated handler.

Source - How to: Store and Retrieve Application Settings Using Isolated Storage