Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Silverlight 3.0 equivalent for BasedOn="{StaticResource {x:Type TextBlock}}"

I am trying to extend a base style for a TextBlock. Simple think in WPF world, should be the same in Silverlight. But I get a error on x:Type.

How can I translate BasedOn="{StaticResource {x:Type TextBlock}}" in Silverlight. Anyone out there who achieved this ?

Thank you.

like image 561
Calin Avatar asked Jan 28 '10 21:01

Calin


2 Answers

There isn't an equivalent to that particular usage in Silverlight. Silverlight only supports string keys for accessing Resources. Hence the use of {x:Type SomeType} as a key doesn't work.

In Silverlight you need to make a complete copy of the controls style. You can do this either by using Blend which has tools for doing this or by copy'n'pasting it from the Silverlight documentation. Control Styles and Templates

Of course once you have a copy of the initial style you can then either modify your copy or create other Styles assigning this copy to BasedOn to create a set of variations.

like image 86
AnthonyWJones Avatar answered Nov 09 '22 04:11

AnthonyWJones


I Think it will work to go a little backwards, you can make your base style

<Style TargetType="Button" x:Key="MyButtonStyle">
    <Setter Property="PropertyName" Value="PropertyValue" />
</Style>

then you can base all buttons on that style

<Style TargetType="Button" BasedOn="{StaticResource MyButtonStyle}" />

Then if you need to add to that style you can just base it on the named style

<Style TargetType="Button" BasedOn="{StaticResource MyButtonStyle}">
    <Setter Property="PropertyName" Value="PropertyValue" />
</Style>

or

<Style TargetType="Button" BasedOn="{StaticResource MyButtonStyle}" x:Key="MyOtherButtonStyle">
    <Setter Property="PropertyName" Value="PropertyValue" />
</Style>
like image 35
Timbot Avatar answered Nov 09 '22 06:11

Timbot