在我的Windows Phone 8應用程序,我有主題設置的頁面如下圖所示:如何更改主題,只要在WP8 C#listpicker選擇值
在listpicker控制我有兩個值Dark
和Light
。當我從listpicker控制選擇Dark
我想改變應用程序的主題:
,並在themelistPicker1_SelectionChanged
方法,我做象下面這樣:
private void themelistPicker1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListPickerItem lpi = (sender as ListPicker).SelectedItem as ListPickerItem;
themename = lpi.Content.ToString();
if (themename == "Dark")
{
App.dark();
}
else
{
App.light();
}
}
,並在App.xaml.cs
頁我已經定義Dark
並定義像下面Light
方法:
using System;
using System.Diagnostics;
using System.Resources;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using GetContacts.Resources;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Media;
namespace GetContacts
{
public partial class App : Application
{
/// <summary>
/// Provides easy access to the root frame of the Phone Application.
/// </summary>
/// <returns>The root frame of the Phone Application.</returns>
/// <summary>
/// Constructor for the Application object.
/// </summary>
public App()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
// Standard XAML initialization
InitializeComponent();
// Phone-specific initialization
InitializePhoneApplication();
// Language display initialization
InitializeLanguage();
// Show graphics profiling information while debugging.
if (Debugger.IsAttached)
{
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = true;
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are handed off to GPU with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
// Prevent the screen from turning off while under the debugger by disabling
// the application's idle detection.
// Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
// and consume battery power when the user is not using the phone.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
}
public static void dark()
{
(App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(12, 12, 54, 145);
(App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.White;
(App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Colors.Gray;
}
public static void light()
{
(App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(12, 12, 54, 145);
(App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.Black;
(App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Colors.White;
}
}
}
但是,當我選擇Dark
主題PhoneBackgroundBrush=Black
,而不是Gray
和PhoneForegroundBrush=white
以及當我選擇Light
主題PhoneBackgroundBrush=Black
而不是White
和PhoneForegroundBrush=Black
。
請問我應該怎麼做,在從listpicker控件選擇值後更改應用程序主題,你有什麼想法嗎?等待回覆。
謝謝
你經歷這個? http://msdn.microsoft.com/en-us/library/windows/apps/ff769545(v=vs.105).aspx – Kulasangar 2014-09-23 12:25:07