Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> WPF >> Property Triggers in WPF
Property Triggers in WPF

Idea about property triggers in WPF
Views: 2019     Comments: 0
by Uttam Misra on 5/12/2011

Property Triggers

These are the most common and basic types of triggers within the WPF programmatic model. They are

basically XAML condition statements that check the state of a property to determine whether to use a

specific style/setter value within the style of the element.

 

The following are the basic steps for creating a property trigger:

 

1.       Create a top-level <Style> XML element in your XAML page and set the TargetType of the

<Style> XML element to {x:Type Button}:

<Style TargetType=”{x:Type Button}”>

 

2.        Within the <Style> entries, define the <Style.Trigger> element:

<Style.Triggers>

 

3.        Within the <Style.Triggers> XML element, create a <Trigger> XML element with the property

to check and the value to compare it to set as attributes for this class:

<Trigger Property=”IsMouseOver” Value=”False”>

</Trigger>

 

4.        Enter the <Setter> XML element to designate the actual property value of the Button control(s)

that will need to be rendered. In this case, the developer can set the property to be modified in the trigger’s condition routine.

<Setter Property=”Background” Value=”Red” />

 

5.        Add a button to the XAML page, with no special settings needed:

<Button VerticalAlignment=”Left”

HorizontalAlignment=”Stretch”

Height=”66”

Name=”btnOne”>Button

</Button>

 

 

The final syntax should resemble the following:

 

<Window x:Class=”PropertyTrigger.Window1”

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

Title=”PropertyTrigger”

>

<Window.Resources>

<Style TargetType=”{x:Type Button}”>

<Style.Triggers>

<Trigger Property=”IsMouseOver” Value=”False”>

<Setter Property=”Background” Value=”Red” />

</Trigger>

</Style.Triggers>

</Style>

</Window.Resources>

<Grid>

<Button VerticalAlignment=”Left”

HorizontalAlignment=”Stretch”

Height=”66”

Name=”btnOne”>Button

</Button>

</Grid>

</Window>

As displayed, the setter property would apply only when the trigger is evaluated to be a False condition.

If the trigger is evaluated to a True value, it will not fire.

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Uttam MisraRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 6357
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.