Windows Phone: how to get accent color in your app
Mood: cheerful
Posted on 2013-01-02 23:20:00
Tags: windowsphone wpdev
Words: 227

As I mentioned in my post about icon design, I'm terrible at art, and I'm also not very good at making apps attractive.

But I do know that a splash of color helps, and since Windows Phone has user-selectable themes, you can use the theme accent color and make the app look "at home" on the phone, since the Start screen will have the theme accent color all over the place.

In XAML, this is very simple, for example for a TextBlock you can use Runs like:


<TextBlock TextWrapping="Wrap">
<Run>Better with a</Run>
<Run Foreground="{StaticResource PhoneAccentBrush}">splash</Run>
<Run>of color!</Run>
</TextBlock>

and in C# you can get a Brush with

Brush accent = Application.Current.Resources["PhoneAccentBrush"] as Brush;

There are a lot of these resources available per theme, including other Brushes, font sizes, etc. Here's a useful reference page that has all of the theme resources.

Note: @YiXueDictionary pointed out that using the "as" operator is a little faster than casting (and looks a little nicer) - see this post for a performance comparison of various casting mechanisms in .NET.
--

See all my Windows Phone development posts.

I'm planning on writing more posts about Windows Phone development - what would you like to hear about? Reply here, on twitter at @gregstoll, or by email at ext-greg.stoll@nokia.com.

--

Interested in developing for Windows Phone? I'm the Nokia Developer Ambassador for Austin - drop me a line at ext-greg.stoll@nokia.com!


This backup was done by LJBackup.