Freigeben über


Windows Phone 8.1 for Developers–Theme Resources

This blog post is part of a series about how Windows Phone 8.1 affects developers. This blog post highlights the Changes made to theme Resources and is written by Alexander Persson at Jayway and was originally posted here.

Introduction

On Windows Phone we have the choice to set our theme to either Light or Dark – this will affect all apps and on top of that we also have the Accent Color to personalize our device even more. Windows 8.1 on the other side hasn’t themes or Accent Color but as the platforms converge we get same API on both platforms – but with slightly different behavior.

 

PhoneThemeManager

We couldn’t force our Windows Phone 8 app out of the box to only use the light theme but PhoneThemeManager made it possible. A single line of code and the app was forced into light theme. Though AppBars required some extra code and MessageBoxes wasn’t themed at all it worked really well.

 

Then came Windows Phone 8.1

With a single line of code in XAML we can force the app to a theme we want without additional code or hacks.

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

In this example it’s done in app.xaml which sets the theme to light across the app. But we are not limited to only set this property in app.xaml but we can also do it on any page or even on any FrameworkElement.

 

Accent Color

By changing accent color the user can get a feel of a more personalized device, and using this color in your app may enhance this feeling. In Windows Phone 8.0 we could do this with:

 Background="{StaticResource PhoneAccentBrush}"

In Windows Phone 8.1 we got a new type of accentcolor resource:

 Background="{ThemeResource SystemColorControlAccentColor}"

This also works in Windows 8.1 apps so that it’s possible to share XAML in universal apps and still take advantage of accent color. But since accent color doesn’t exist on Windows 8.1 the color we get will always be Blueberry.

 

No more restarts

Another new feature that comes with Windows Phone 8.1 is that the need to restart the app after changing theme is gone if you are using ThemeResource in your bindings. So changing accent color or theme will take effect immediately which is really cool.