Windows Phone: how to get accent color in your app

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 greg@gregstoll.com.

Leave a comment