Log in

No account? Create an account
Windows Phone: how to get accent color in your app - Greg [entries|archive|friends|userinfo]

[ website | gregstoll.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

[Links:| * Homepage * Mobile apps (Windows Phone, Win8, Android, webOS) * Pictures * LJBackup * Same-sex marriage map * iTunesAnalysis * Where's lunch? ]

Windows Phone: how to get accent color in your app [Jan. 2nd, 2013|11:20 pm]
[Tags|, ]
[Current Mood |cheerfulcheerful]

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>

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.