Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a global Style in Windows Phone 7?

I want to use a global Style in WP7, something like:

<Style TargetType="Button">
//some code here
</Style>

The problem is that this code does not seem to work in WP7.

I know how to add x:Key to the Style and after that how to reference it as a StaticResource, but this is not my case. I want a global Style.

like image 915
Kate Brown Avatar asked Mar 21 '11 16:03

Kate Brown


1 Answers

If I create an application wide (global) style like this:

<Application.Resources>
    <Style x:Key="MyTextNormalStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}" />
        <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}" />
    </Style>
</Application.Resources>

Then I can refer to it like this:

<TextBlock Text="some text" Style="{StaticResource MyTextNormalStyle}" />
like image 194
Matt Lacey Avatar answered Oct 19 '22 00:10

Matt Lacey