views:

104

answers:

1

I would like to define a theme for my Windows Phone 7 application, to be applied at application launch regardless of the system theme set by the "Settings" phone menu. How can this be done?

I see on MSDN that Fill="{StaticResource PhoneAccentBrush}" allows the control using that brush to respond to system-wide theme changes. How can I do the same thing: to allow the control to get its brush, not from the system settings, but from my application settings?

And where should I put those settings, in order to have one style settings file that I can access from anywhere in my application?

+2  A: 

There's no theme specific API in Silverlight. What you have is one or several resources dictionnary/ies that you can use to define a set of styles to be applied to your controls.

in Theme1.xaml file :

<Style x:Key="HeadingStyle" TargetType="{x:Type Label}">
     <Setter Property="Foreground" Value="Black"/>
</Style>

in Theme2.xaml file :

<Style x:Key="HeadingStyle" TargetType="{x:Type Label}">
  <Setter Property="Foreground" Value="Red"/>
</Style>

in App.xaml (the default theme or reference a default.xaml file):

<Application.Resources>
   <Style x:Key="HeadingStyle" TargetType="{x:Type Label}">
    <Setter Property="Foreground" Value="blue"/>
  </Style>
</Application.Resources>

To change the current "theme" :

Application.Current.Resources = Application.LoadComponent(new Uri("Theme2.xaml", UriKind.RelativeOrAbsolute));

I don't have right now the RTM tools installed so I can't test this code.

Matthieu
You pretty much nailed it. According to the documentation, you can only override the system theme if you explicitly modify the control properties that are affected by a theme. Link: http://msdn.microsoft.com/en-us/library/ff402557%28VS.92%29.aspx
Dennis Delimarsky
Thank you for your answers!
Manu