Search code examples
wpfsilverlightexpression-blendsilverlight-5.0

Silverlight inheritance like WPF


to minimize the code-lines in WPF all my controls inherit from a style called BaseControlStyle that looks something like this:

<Style x:Key="BaseControlStyle" TargetType="{x:Type FrameworkElement}">
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Opacity" Value="0.5"/>
        </Trigger>
    </Style.Triggers>
</Style>

A new Button Style would look like this:

<Style x:Key="ButtonStyle" TargetType={x:Type Button} BasedOn="{StaticResource BaseControlStyle}">
....
</Style>

But being new to Silverlight I could not find a answer whether it is possible to transfer this BaseControlStyle to into a SilverlightBaseControlStyle that uses VisualStateManager (or something else) or not?


Solution

  • Unfortunately, there's no such thing as property triggers in Silverlight - Visual States are used instead, which means handling appearance in code. For such tasks as in your case it is easier to create a copy of a standard Button's style and change animations in it's default ControlTemplate. Sometimes it is also useful to use behaviors.