Recommended


Silverlight Hosting

Skip Navigation LinksHome / Tips / View Tip

Tip: What is control styling?

+ Add to SilverlightShow Favorites
0 comments   /   posted by Ivan Dragoev on Nov 14, 2008
(1 votes)
Categories: Styles and Templates

Styling control is a very easy way to tweak the minor visual characteristic of the control such as foreground and background colors, the font style and size, padding, etc. Usually the styles are stored as resources which allows you to reuse them whenever you want.

The Style has TargetType specifying the type of the object the style can be applied to and a key used to identify the style. The Style contains numerous Setters, which describe the values which you want to set to specific properties.

To apply style to a control simply specify the Style property of the control to point to the static resource with a specific key name.

   1: <Grid>
   2:     <Grid.Resources>
   3:         <Style TargetType="Button" x:Key="myButtonStyle">
   4:             <Setter Property="Width" Value="100" />
   5:             <Setter Property="Height" Value="25" />
   6:             <Setter Property="Foreground" Value="#FF87091F"/>
   7:             <Setter Property="Padding" Value="2"/>
   8:             <Setter Property="BorderThickness" Value="4"/>
   9:             <Setter Property="FontWeight" Value="Bold" />
  10:             <Setter Property="FontFamily" Value="Portable User Interface" />
  11:         </Style>
  12:     </Grid.Resources>
  13:     <Button Content="Click Me!" Style="{StaticResource myButtonStyle}">
  14:     </Button>        
  15: </Grid>

 That's it!

Share


Comments

Comments RSS RSS
No comments

Add Comment

 
 

   
  
  
   
 Refresh