Silverlight 3 Quick Tip Styling Improvements

Silverlight 3 bring long-awaited improvements in styling mechanism: “BasedOn” mechanism, Merged Resource Dictionaries and eliminates “write once” style setting behavior. Let’s see those features.

BasedOn

Styles can be “derived” from one another. Perfect for cascading/inheriting styles.

Let’s define style for a… Button (well, in demos it is always a Button, TextBox, etc. ;) )

<Style x:Key="BaseButtonStyle" TargetType="ButtonBase">
     <Setter Property="Width" Value="100"/>
     <Setter Property="Height" Value="25"/>
     <Setter Property="Margin" Value="5"/>
</Style>

To “derive” from existing style we should specify BasedOn property

<Style x:Key="DerivedButtonStyle" TargetType="ButtonBase" 
  BasedOn="{StaticResource BaseButtonStyle}">
      <Setter Property="Background" Value="Red"/>
      <Setter Property="BorderBrush" Value="Blue"/>
      <Setter Property="BorderThickness" Value="3"/>
</Style>

more here
This entry was posted in Design, tutorial and tagged , , , , , . Bookmark the permalink.