Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

DataTrigger

DataTrigger

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

<Grid>

        <Grid.Resources>

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

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

                <Style.Triggers>

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

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

                    </DataTrigger>

                </Style.Triggers>

            </Style>

        </Grid.Resources>

      <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"/>

        </ComboBox>

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

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

      </StackPanel>

</Grid>