Benutzer:MovGP0/WPF/Triggers
< Benutzer:MovGP0 | WPF
MovGP0 | Über mich | Hilfen | Artikel | Weblinks | Literatur | Zitate | Notizen | Programmierung | MSCert | Physik |
Triggers[Bearbeiten | Quelltext bearbeiten]
PropertyTrigger[Bearbeiten | Quelltext bearbeiten]
<ResourceDictionary (...)>
<Style TargetType="{x:Type local:MyControl}">
<Setter Property="Background" Value="White">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyControl}">
<Grid Background="{TemplateBinding Background}">
<!-- ... -->
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Green" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
MultiTrigger[Bearbeiten | Quelltext bearbeiten]
<ResourceDictionary (...)>
<Style TargetType="{x:Type local:MyControl}">
<Setter Property="Background" Value="White">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyControl}">
<Grid Background="{TemplateBinding Background}">
<TextBox x:Name="textBox"
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="Text" Value="Hello" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Green" />
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="5" TargetName="textBox" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
EventTrigger[Bearbeiten | Quelltext bearbeiten]
<ResourceDictionary (...)>
<Style TargetType="{x:Type local:MyControl}">
<Setter Property="Background" Value="White">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyControl}">
<Grid Background="{TemplateBinding Background}">
<TextBox x:Name="textBox"
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
To="Green" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
To="White" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
DataTrigger[Bearbeiten | Quelltext bearbeiten]
MultiDataTrigger[Bearbeiten | Quelltext bearbeiten] |