2014-08-28 49 views

回答

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

现在在你的你的MainPage可以重新初始化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(); 

但是,这是未经测试应该给你非常关于如何在保存和加载设置上应用它然后应用它的基本想法