Creating a data trigger
As the name says, the data trigger applies property values to perform a set of actions on the Data
that has been bound to the UIElement
. This is represented by the <DataTrigger>
element.
In this recipe, we will learn how to create a trigger that acts on the underlying data.
Getting ready
Let's get started with creating a new WPF project. Open the Visual Studio and create a project called CH06.DataTriggerDemo
.
How to do it...
Follow these simple steps to create a data trigger that will act to change the Background
and Content
property of a Label
, based on the radio button selection:
From the
Solution Explorer
, open theMainWindow.xaml
file.Let's divide the
Grid
panel into two columns:
<Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions>
Now insert a
Label
of150
x100
dimension at column0
(zero) and set itsForeground
property toWhite
:
<Label Width="150" Height="100" Grid.Column...