WP7 - 如何让用户设置应用主题

时间:2014-08-28 21:34:07

标签: windows-phone-7

我的应用有10页,所有这些都有黑色背景。我想让用户在我的应用程序中使用radioButton更改所有页面的背景颜色。我怎样才能以最简单的方式做到这一点?

2 个答案:

答案 0 :(得分:0)

浏览这些博客

1. Theme Forcing for Windows Phone 7或,

2. Windows Phone Mango Custom application Theme

这些可能对您有所帮助。您可以研究这些并进行修改,将它们放入您的设置页面。

谢谢你:)

答案 1 :(得分:0)

好的,所以你有10页,每页都要通过设置菜单更改这些页面的背景颜色。您可以使用Windows Phone IsolatedStorageSettings

首先,您要初始化IsolatedStorageSettings。你可以这样做:

IsolatedStorageSettings MyAppSettings = IsolatedStorageSettings.ApplicationSettings;

然后你必须为它设置一个默认值,这样就不会抛出异常。你可以这样做:

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 
        }
}

现在,您可以在主页中重新初始化IsolatedStorageSettings。完成后,您将需要获取设置的值,并根据您想要更改背景颜色的值。要读取值:

string Sortval = (string)MyAppSettings["PageBackgroundColor"];

您可以在以下位置添加:

protected override void OnNavigatedTo(NavigationEventArgs e)
{

}

或者

public MainPage
{
   InitializeComponent();
}

<强> Remember that public MainPage will only run once and the OnNavigatedTo runs every time the page is loaded so if you want to update the background color right after adding the setting, OnNavigatedTo is the way to go but if you want to apply the changes after a restart, public Mainpage is it.

现在要读取值并进行更改,您需要执行以下操作:

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的值并保存值,就像这样:

 MyAppSettings.Remove("PageBackgroundColor");
 MyAppSettings.Add("PageBackgroundColor", "your hex color");
 MyAppSettings.Save();

这是未经测试但是它应该为您提供有关如何在保存和加载设置方面执行此操作然后应用它的基本概念