Property trigger

The most common trigger is the property trigger, which can be simply defined in XAML with a <Trigger> element. It triggers when a specific property on the owner control changes to match a specified value:

<Style TargetType="{x:Type CheckBox}"> 
  <Style.Triggers> 
     <Trigger Property="IsChecked" Value="True"> 
       <Setter Property="Background" Value="LightGreen"/> 
     </Trigger> 
     <Trigger Property="IsChecked" Value="False"> 
       <Setter Property="Background" Value="Red"/> 
     </Trigger> 
  </Style.Triggers> 
</Style> 

The preceding XAML code snippet creates a style for a checkbox control having two triggers associated with its property IsChecked. When the value is True, the background of the checkbox will be set to LightGreen, and when it is False, the background will be set to Red.

If we run the example, with a checkbox control in it, we will see the following results based on the checked status of it:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.84.155