XML
  Home arrow XML arrow Page 5 - More on Triggers and Styles and Control Te...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

More on Triggers and Styles and Control Templates
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2007-07-03

    Table of Contents:
  • More on Triggers and Styles and Control Templates
  • Control Templates
  • Control Templates and Styles
  • Content Presenters
  • The Real Work

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    More on Triggers and Styles and Control Templates - The Real Work


    (Page 5 of 5 )

    The last little bit of work is getting the padding right. Since the content presenter doesn’t have its own Padding property, we can’t bind the Padding property directly (it doesn’t have a Background property, either, which is why we usedRectangleand itsFillproperty). For properties that don’t have a match on the content presenter, you have to find mappings or compose the elements that provide the functionality that you’re looking for. For example,Paddingis an amount of space inside of a control.Margin, on the other hand, is the amount of space around the outside of a control. Since they’re both of the same type,System.Windows.Thickness, if we could map thePaddingfrom the inside of our button to the outside of the content control, our game would look very nice:

      <Style TargetType="{x:Type Button}">
        <Setter Property="Background" Value="White" />
       
    <Setter Property="Padding" Value="10,5" />
       
    ...
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
              <Grid>
               
    <Rectangle Fill="{TemplateBinding Property=Background}" />
               
    <ContentPresenter
                 
    Content="{TemplateBinding Property=Content}" 
               Margin="{TemplateBinding Property=Padding}" /> 
             
    </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
        ...
     
    </Style>

    Figure 5-20 shows our completed tic-tac-toe variation.


    Figure 5-20.  Binding the Padding property to the Margin property (Color Plate 15)

    Like the mapping betweenPaddingandMargin, building up the elements that give you the look you want and binding the appropriate properties from the templated parent is going to be a lot of the work of creating your own control templates.

    Where Are We?

    Styles enable you to define a policy for setting the dependency properties of visual elements. The sets of properties can be named and applied manually or programmatically by name, or applied automatically using element-typed styles. In addition to providing constant dependency-property values, styles can contain condition-based property values based on other dependency properties, data properties, or events. And, if setting properties isn’t enough to get the look you’re after, you can replace a lookless control’s entire rendering behavior using a control template.

    But that’s not all there is to styles. For information about how animations work, you’ll want to read Chapter 8, and for information about styles as related to resources, themes, and skins, you’ll want to read Chapter 6.


    * Moving groups of settings into styles also allows for easier skinning and theming, as described in Chapter 6.

    * The null value is set via a XAML markup extension, which you can read more about in Appendix A.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Programming Windows Presentation...
     

    Buy this book now. This article is excerpted from chapter five of the book Programming Windows Presentation Foundation, written by Chris Sells and Ian Griffiths (O'Reilly; ISBN: 0596101139). Check it out today at your favorite bookstore. Buy this book now.

    XML ARTICLES

    - More on Triggers and Styles and Control Temp...
    - Looking at Triggers with Styles and Control ...
    - A Closer Look at Styles and Control Templates
    - Styles and Control Templates
    - Properties and More in XAML
    - Elements and Attributes in XAML
    - XAML in a Nutshell
    - Importing XML Files into Access 2007
    - Using MSXML3.0 with VB 6.0
    - MSXML, concluded
    - MSXML, continued
    - MSXML Tutorial
    - Generating XML Schema Dynamically Using VB.N...
    - XSL Transformations using ASP.NET
    - Applying XSLT to XML Using ASP.NET

    Iron Speed




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway