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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With