xamlsilverlight-2.0code-reusestyling

Inheritance in Silverlight 2 Styles


I want to build up styles in XAML, e.g.

<UserControl.Resources>
    <Style x:Key="MyStyle" TargetType="TextBlock">
        <Setter Property="Margin" Value="2,2,2,2" />
        <Setter Property="Foreground" Value="DarkRed" />
    </Style>
    <Style x:Key="MyBoldStyle" TargetType="TextBlock">
        <Setter Property="Style" Value="{StaticResource MyStyle}" />
        <Setter Property="FontWeight" Value="Bold" />
    </Style>
</UserControl.Resources>

But this does not work. (In Silverlight 2) How can I make one inherit from the other?


June 2010 Update: Style Inheritance is in Silverlight 3, use BasedOn="{StaticResource MyStyle}


Solution

  • Nevermind. I found the answer in MacDonald's Pro Silverlight 2 in C# 2008:

    alt text
    (source: apress.com)

    "If you've used styles in WPF, you'll find that Silverlight styles are dramatically scaled back ... [for example, you can't] create styles that inherit from other styles."

    Too bad. Maybe in Silverlight 3.