How many types of triggers are in WPF?
There are five types of triggers supported by WPF; they are:
1-Data Trigger
<DataTemplate> <Grid Margin="0 5 0 0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image x:Name="viewImage" Grid.Row="0" Width="100"
Height="60" HorizontalAlignment="Center"
Source="{Binding Picture}" Stretch="Fill" />
<TextBlock x:Name="viewText" Grid.Row="1" Margin="0 5 0 0"
HorizontalAlignment="Center"
FontWeight="Black" Foreground="Green" Text="{Binding Title}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Picture}" Value="{x:Null}">
<Setter TargetName="viewImage" Property="Source" Value="/Images/noImage.png" />
<Setter TargetName="viewText" Property="Text" Value="No Image Available" />
<Setter TargetName="viewText" Property="Foreground" Value="Red" />
</DataTrigger> </DataTemplate.Triggers></DataTemplate>
3-MultiTrigger
<Style x:Key="MulitTriggerButtonStyle" TargetType="Button">
<Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions>
<Condition Property="IsPressed" Value="True" />
<Condition Property="Background" Value="BlanchedAlmond" />
</MultiTrigger.Conditions> <MultiTrigger.Setters>
<Setter Property="Foreground" Value="Blue" />
<Setter Property="BorderThickness" Value="5" />
<Setter Property="BorderBrush" Value="Blue" />
</MultiTrigger.Setters> </MultiTrigger> </Style.Triggers></Style>
3
Property Trigger
<Style x:Key="styleWithTrigger" TargetType="Rectangle"> <Setter Property="Fill" Value="LightGreen" /> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Fill" Value="Red" /> </Trigger> </Style.Triggers> </Style> <Rectangle Style="{StaticResource styleWithTrigger}"></Rectangle>
No comments:
Post a Comment