July 2017
Beginner
466 pages
9h 37m
English
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
Read now
Unlock full access