Galin Iliev's blog

Software Architecture & Development

Silverlight 4: Setting a global application theme

I am creating a SL4 application and I was looking for a way to make more shinier. Of course themes come to play here but the big questions is “How to setup a global theme?”

Search results returned a bunch of ideas with a lot of code like merging dictionaries etc… And I was thinking it should be simple, very simple.

I came across this post about Silverlight4 Toolkit April 2010 release. But still what suggested there didn’t work for me:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="ToolkitSamplesApril10.App"
             xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             toolkit:BureauBlackTheme.IsApplicationTheme="True">
    <Application.Resources>
    </Application.Resources>
</Application>

For some reason the highlighted part failed come into play. No result was seen…

So I found this very, very simple way. Just put those two lines in App.xaml.cs:

using ActiveTheme = System.Windows.Controls.Theming.BureauBlackTheme;
....
private void Application_Startup(object sender, StartupEventArgs e)
{
    ActiveTheme.SetIsApplicationTheme(this, true);
    this.RootVisual = new MainPage();
}

Hope this helps,

Loading