Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College



DataTrigger operation is similar to the previously known PropertyTigger, except that in this case any of data control expression can be used as the source of the Trigger.

Example X.3 DataTrigger

X.3. DataTrigger



            <Style x:Key="DataTrigger" TargetType="Label">

                <Setter Property="Foreground" Value="White" />


                   <DataTrigger Binding="{Binding ElementName=cbElectric, Path=SelectedIndex}" Value="3">

                        <Setter Property="Foreground" Value="Green" />





      <StackPanel Orientation="Horizontal">

        <Label Content="What is the electric current SI unit?" Height="30" />

        <ComboBox x:Name="cbElectric" Width="100" Height="30">

                <ComboBoxItem Content="coulomb"/>

                <ComboBoxItem Content="farad"/>

                <ComboBoxItem Content="volt"/>

                <ComboBoxItem Content="amper"/>


        <Label Content="Right!" Height="30"

               Style="{StaticResource ResourceKey=DataTrigger}"/>