How to set themes/styles in a Windows Universal App

All the styles which used to be present there have been moved to a platform-level file ‘generic.xaml’. This means that a basic resource file would always be present as a part of your platform and you do not need to add it to every individual project! Of course, it does bring up the question of how to customize the styles, which styles are already present and which styles need to be created and so on. As expected, for modifying existing styles and adding new styles, a new resource file needs to be created which can override the existing styles. There are three sets of brushes, thicknesses etc. for the three different themes (Default, Light, High Contrast). So when we set the theme for an application, we immediately know which colors would be applied throughout the app.
(Starting with styling a Windows 8.1 application, applicable to Windows 10 too).

Application.RequestedTheme property – There are two built in themes: “Light” and “Dark“. By default your app runs using the “Dark” theme (in the themeresources.xaml file, the key name for the “Dark” resources is “Default“). … There is also a “HighContrast” theme that uses system values, but apps and app code use a different technique for switching the app to high contrast. The RequestedTheme property is ignored if the user is running in high contrast mode. See Supporting high contrast themes and XAML high contrast style sample.

Therefore, if you want to follow the “Light“/”Dark” style you have to put in the App.xaml:

<Application
    x:Class="MyProject.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyProject.Styles"
    RequestedTheme="Light"> 

... or "Dark"
Annunci

Informazioni su Enzo Contini

Electronic engineer
Questa voce è stata pubblicata in Windows, Windows Phone/Mobile. Contrassegna il permalink.

Lascia un Commento/Leave a comment

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...