Recommended

More from Ivan Dragoev

Skip Navigation LinksHome / Tips / View Tip

Tip: What is control styling?

+ Add to SilverlightShow Favorites
1 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
  • RE: Tip: What is control styling?  

    posted by SR on May 30, 2010 19:48
    Thanks for cool tip

Add Comment

 
 

   
  
  
   
Please add 4 and 6 and type the answer here:

Help us make SilverlightShow even better and win a free t-shirt. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need a material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)