Silverlight 3 Quick Tip #10: Styling Improvements

Monday, June 22, 2009

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}"> ...