XML
  Home arrow XML arrow Page 3 - Looking at Triggers with Styles and Contro...
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 
VeriSign Whitepapers 
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

Looking at Triggers with Styles and Control Templates
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2007-06-28

    Table of Contents:
  • Looking at Triggers with Styles and Control Templates
  • Triggers
  • Multiple Triggers
  • Data Triggers

  • 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
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Looking at Triggers with Styles and Control Templates - Multiple Triggers


    (Page 3 of 4 )

    While you can set as many properties as you like in a property trigger, there can be more than one trigger in a style. When grouped together under the Style.Triggers element, multiple triggers act independently of each other.

    For example, we can update our code so that if the mouse is hovering over one of our buttons, it’ll be colored yellow and if the button has focus (the tab and arrow keys move focus around), it’ll be colored green, as in Example 5-26. Figure 5-9 shows the result of one cell having focus and another with the mouse hovering.

    Example 5-26.  Multiple property triggers

    <Style TargetType="{x:Type Button}">
     
    ...
     
    <Style.Triggers>
       
    <Trigger Property="IsMouseOver" Value="True" >
          <Setter Property="Background" Value="Yellow" />
       
    </Trigger>
        <Trigger Property="IsFocused" Value="True" >
         
    <Setter Property="Background" Value="LightGreen" />
       
    </Trigger>
      </Style.Triggers>
    </Style>


    Figure 5-9.  Multiple property triggers in action

    If multiple triggers set the same property, the last one wins. For example, in Figure 5-9, if a button has focus and the mouse is over it, the background will be light green because the trigger for theIsFocusedtrigger is last in the list of triggers.

    Multi-Condition Property Trigger

    If you’d like to check more than one property before a trigger condition is activated—e.g., the mouse is hovering over a button and the button content is empty—you can combine multiple conditions with a multiple-condition property trigger, as in Example 5-27.

    Example 5-27.  A multi-property trigger

    <Style TargetType="{x:Type Button}">
     
    ...
     
    <Style.Triggers>
       
    <MultiTrigger>
         
    <MultiTrigger.Conditions>
           
    <Condition Property="IsMouseOver" Value="True" />
           
    <Condition Property="Content" Value="{x:Null}" />
         
    </MultiTrigger.Conditions>
         
    <Setter Property="Background" Value="Yellow" />
       
    </MultiTrigger>
     
    </Style.Triggers>
    </Style>

    Multi-condition property triggers check all of the properties’ values to be set as specified, not just one of them. Here, we’re watching for both a mouse hover and for the content to be null,* reflecting the game logic that only clicking on an empty cell will result in a move.

    Figure 5-10 shows the yellow highlight on an empty cell when the mouse hovers, and Figure 5-11 shows the yellow highlight absent when the mouse hovers over a full cell.


    Figure 5-10.  Multi-condition property trigger with hovering and null content


    Figure 5-11.  Multi-condition property trigger not triggering as content is not null

    Property triggers are great for noticing when the user is interacting with a control displaying your program’s state. However, we’d also like to be able to notice when the program’s state itself changes, such as when a particular player makes a move, and update our style settings accordingly. For that, we have data triggers.

    More XML Articles
    More By O'Reilly Media


       · 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





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