Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight generic.xaml

Can I use generic.xaml in Silverlight to set the style of all TextBlock in the application?

<ResourceDictionary xmlns="http://schemas.microsoft.com/client/2007"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="TextBlock">
        <Setter Property="Foreground"
                Value="White" />
        <Setter Property="FontSize"
                Value="24" />
    </Style>   
</ResourceDictionary>

I was expecting this to work but it doesn't :-(

Whats the simplest way to apply styles across a whole application??

Thanks, Mark

EDIT

Thanks for your response. I'm not getting an error, the styles just aren't being applied. All the examples that I found on the internet (including the ones you have listed) are all for styling custom controls. This I can do, but I'd like to just style the default controls:

<TextBlock Text="Style me!!" Grid.Row="2"  />

Do I need to add reference to the generic.xaml from page.xaml?? Do I need to name and reference the generic.xaml style as a resource??

Thanks again, Mark

like image 650
Mark Cooper Avatar asked Jul 14 '26 15:07

Mark Cooper


2 Answers

In Silverlight 4, you can use implicit styling!

like image 67
gius Avatar answered Jul 17 '26 19:07

gius


Setting Styles generically/automatically by setting the TargetType and omitting a ResourceKey only works in WPF, not Silverlight.

If you want to have a Style available throughout your application you can add it to the Resources collection in your App.xaml, but to use it it will need a x:Key and you will have to apply it individually as a StaticResource binding to each instance of your target type that you want to use it.

like image 26
Gordon Mackie JoanMiro Avatar answered Jul 17 '26 20:07

Gordon Mackie JoanMiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!