我在 Visual Studio 中有一个 UWP 项目。我想保留我的设置。示例:文本环绕在默认情况下处于打开状态。当用户更改此值时,我的应用程序将保留此值,并且我的应用程序将在加载时加载到我的设置中。
在 UWP 中这很简单:
它将数据对象存储在val给定的位置。
功能:
public static void SaveSettings(string val, object data)
{
ApplicationData.Current.LocalSettings.Values[val] = data.ToString();
}
public static string GetSettings(string val, string defaultValue = "")
{
return ApplicationData.Current.LocalSettings.Values[val] as string ?? defaultValue;
}
用法:
//Save data false for the value "TextWrapping":
SaveSettings("TextWrapping", false);
//Retrieve the data from "TextWrapping" and convert it back to bool
bool TextWrapping = bool.Parse(GetSettings("TextWrapping"));
//Usage of the defaultValue:
//When no data has ever been saved to the value "TextWrapping" it is null. So the function returns the provided defaultValue:
bool TextWrapping = bool.Parse(GetSettings("TextWrapping"), "false");
这里官方文档