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

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

Links
[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]
Previous Entry Share Next Entry
[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>
</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!
LinkReply