In my windows phone 8 application, I have theme setting's page like below:
In the listpicker control I have two values Dark
and Light
. And when I select Dark
from listpicker control I want to change the theme of the application:
And In the themelistPicker1_SelectionChanged
method, I am doing like below:
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();
}
}
And in the App.xaml.cs
page I have define Dark
and Light
method defined like below:
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;
}
}
}
But when I select Dark
theme PhoneBackgroundBrush=Black
instead of Gray
and PhoneForegroundBrush=white
and when I select Light
theme PhoneBackgroundBrush=Black
instead of White
and PhoneForegroundBrush=Black
.
Kindly suggest me what I should do, to change the application theme after selection of value from listpicker control,do you have any idea? waiting for reply.
Thanks
I have an idea. Use ThemeManager developed by Jeff Wilcox By using ThemeManager you can change theme of Application.
Install ThemeManager Library in Nuget Packages & change your code like this..
private void themelistPicker1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListPickerItem lpi = (sender as ListPicker).SelectedItem as ListPickerItem;
themename = lpi.Content.ToString();
if (themename == "Dark")
{
ThemeManager.ToDarkTheme();
}
else
{
ThemeManager.ToLightTheme();
}
}
Hope this Helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.