Windows phone 8 Comment être toujours sur un thème même si le thème du téléphone a changé

Mon application est généralement conçue pour dark thème dark , et j’utilise StaticResources Ainsi, si l’utilisateur modifie le thème de son téléphone pour l’ light l’application devient illisible et inutilisable.

J’ai essayé de changer manuellement la couleur de chaque élément et d’éviter d’utiliser StaticResources et des choses comme:

 Style="{StaticResource PhoneTextLargeStyle}" 

et StaticResources pour la police et la couleur. Mais c’est un travail difficile.

Comment puis-je changer globalement le thème de mon application si le thème du téléphone est sombre? (c’est une application windows phone 8)

Mise à jour : Depuis la publication de Windows Phone 8.1 , vous pouvez définir l’atsortingbut RequestedTheme sur n’importe quel contrôle, ou même au niveau de l’application, pour remplacer le thème défini par les utilisateurs dans les parameters .

Exemple pour forcer le thème Lumière:

En code , dans le constructeur de la classe App:

 ///  /// Provides application-specific behavior to supplement the default Application class. ///  public sealed partial class App : Application { private TransitionCollection transitions; ///  /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). ///  public App() { this.RequestedTheme = ApplicationTheme.Light; this.InitializeComponent(); this.Suspending += this.OnSuspending; } } 

Ou en XAML :

   

Pour l’ancien modèle d’application Windows Phone 8 :

Il est bien sûr recommandé dans les consignes de conception d’utiliser les ressources de thème pour vous assurer que votre application fonctionne avec tous les thèmes et couleurs d’accent.

Cependant si vous voulez vraiment forcer le thème sombre, voici une solution fournie par Rudy Huyn sur son blog: http://www.rudyhuyn.com/blog/2013/01/18/forcer-un-theme-sous-windows -phone-8 /

L’idée est d’append une méthode dans votre classe d’application qui remplacera tous les brosses système avec les couleurs du thème sombre:

 private void DarkTheme() { ((SolidColorBrush)Resources["PhoneRadioCheckBoxCheckBrush"]).Color = ((SolidColorBrush)Resources["PhoneRadioCheckBoxBorderBrush"]).Color = ((SolidColorBrush)Resources["PhoneForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00); ((SolidColorBrush)Resources["PhoneContrastForegroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00); ((SolidColorBrush)Resources["PhoneContrastBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneDisabledBrush"]).Color = Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneProgressBarBackgroundBrush"]).Color = Color.FromArgb(0x19, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneTextCaretBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00); ((SolidColorBrush)Resources["PhoneTextBoxBrush"]).Color = Color.FromArgb(0xBF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneTextBoxForegroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00); ((SolidColorBrush)Resources["PhoneTextBoxEditBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneTextBoxReadOnlyBrush"]).Color = Color.FromArgb(0x77, 0x00, 0x00, 0x00); ((SolidColorBrush)Resources["PhoneSubtleBrush"]).Color = Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneTextBoxSelectionForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneButtonBasePressedForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneTextHighContrastBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneTextMidContrastBrush"]).Color = Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneTextLowContrastBrush"]).Color = Color.FromArgb(0x73, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneSemitransparentBrush"]).Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x00); ((SolidColorBrush)Resources["PhoneChromeBrush"]).Color = Color.FromArgb(0xFF, 0x1F, 0x1F, 0x1F); ((SolidColorBrush)Resources["PhoneInactiveBrush"]).Color = Color.FromArgb(0x33, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneInverseInactiveBrush"]).Color = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC); ((SolidColorBrush)Resources["PhoneInverseBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); ((SolidColorBrush)Resources["PhoneBorderBrush"]).Color = Color.FromArgb(0xBF, 0xFF, 0xFF, 0xFF); } 

Ensuite, dans le constructeur de l’application, vous vérifiez si le thème Light est activé et, le cas échéant, vous le remplacez:

 if ((Visibility) Resources["PhoneLightThemeVisibility"] == Visibility.Visible) { DarkTheme(); } 

Je voulais juste recommander le paquet de nugets ‘Windows Phone Theme Manager’ de Jeff Wilcox comme moyen facile d’implémenter cette fonctionnalité pour les thèmes clairs et sombres.

http://www.nuget.org/packages/PhoneThemeManager/

Ajoutez simplement un appel de fonction au constructeur de l’application:

 ThemeManager.ToDarkTheme(); 

ou

 ThemeManager.ToLightTheme();