Windows phone 7 WP7-如何让用户设置应用程序主题
我的应用程序有10个页面,所有页面都有黑色背景。我想让用户在我的应用程序中使用radioButton更改所有页面的背景色。我怎样才能以最简单的方式做到这一点?浏览这些博客 或者 这些可能对你有帮助。您可以研究这些内容并进行修改,以将其放在设置页面中Windows phone 7 WP7-如何让用户设置应用程序主题,windows-phone-7,Windows Phone 7,我的应用程序有10个页面,所有页面都有黑色背景。我想让用户在我的应用程序中使用radioButton更改所有页面的背景色。我怎样才能以最简单的方式做到这一点?浏览这些博客 或者 这些可能对你有帮助。您可以研究这些内容并进行修改,以将其放在设置页面中 谢谢:)好的,您有10页,每一页上您都想通过设置菜单更改这些页面的背景颜色。您可以使用Windows Phone隔离存储设置 首先,要初始化IsolatedStorageSettings。您可以这样做: IsolatedStorageSetting
谢谢:)好的,您有10页,每一页上您都想通过设置菜单更改这些页面的背景颜色。您可以使用Windows Phone
隔离存储设置
首先,要初始化IsolatedStorageSettings。您可以这样做:
IsolatedStorageSettings MyAppSettings = IsolatedStorageSettings.ApplicationSettings;
MyAppSettings.Remove("PageBackgroundColor");
MyAppSettings.Add("PageBackgroundColor", "your hex color");
MyAppSettings.Save();
然后您必须为它设置一个默认值,这样它就不会引发异常。您可以这样做:
MyAppSettings.Add("PageBackgroundColor", "#000000"); // you can set whatever the default colour you want here. i.e. Black
我认为最好的地方是将此代码添加到:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("PageBackgroundColor"))
{
// Don't do anything because you've already set the default background colour for the pages
}
else
{
// add the default color
}
}
现在,您可以在主页上重新初始化隔离存储设置
。完成后,您将需要获取设置的值,并根据该值更改背景色。要读取值,请执行以下操作:
string Sortval = (string)MyAppSettings["PageBackgroundColor"];
您可以将其添加到:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
或
请记住,公共主页只会运行一次,而OnNavigatedTo会在每次加载页面时运行。因此,如果您想在添加设置后立即更新背景颜色,OnNavigatedTo是一种方法,但如果您想在重新启动后应用更改,则可以使用公共主页。
现在,要读取并更改该值,您需要执行以下操作:
string val = (string)MyAppSettings["PageBackgroundColor"];
if (val == "#000000")
{
//change to black
}
else if (val == "your hex color")
{
//change to whatever color
}
else if (val == "another hex color")
{
//...
}
现在,要保存要在设置页面中重新初始化的IsolatedStorageSettings
值,并保存这些值,如下所示:
IsolatedStorageSettings MyAppSettings = IsolatedStorageSettings.ApplicationSettings;
MyAppSettings.Remove("PageBackgroundColor");
MyAppSettings.Add("PageBackgroundColor", "your hex color");
MyAppSettings.Save();
这是未经测试的,但它应该能让您了解如何保存和加载设置,然后应用它的基本方法也许我用错了词。我想允许用户在我的应用程序的“设置”页面中更改此颜色