Use
animations[
^]!
Assume you have following XAML:
<Window x:Class="WpfApplication7.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style
TargetType="Label">
<Setter
Property="RenderTransform">
<Setter.Value>
<ScaleTransform x:Name="transform"></ScaleTransform>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger
RoutedEvent="MouseEnter">
<BeginStoryboard
Name="zoomIn">
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="RenderTransform.ScaleX"
To="3"
Duration="00:00:00.25"></DoubleAnimation>
<DoubleAnimation
Storyboard.TargetProperty="RenderTransform.ScaleY"
To="3"
Duration="00:00:00.25"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger
RoutedEvent="MouseLeave">
<BeginStoryboard
Name="zoomOut">
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="RenderTransform.ScaleX"
To="1"
Duration="00:00:00.25"></DoubleAnimation>
<DoubleAnimation
Storyboard.TargetProperty="RenderTransform.ScaleY"
To="1"
Duration="00:00:00.25"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<StackPanel Name="_stackPanel">
<Button Click="Button_Click">Add Panel</Button>
</StackPanel>
</Grid>
</Window>
and an eventhandler defined as follows:
private void Button_Click(object sender, RoutedEventArgs e) {
_stackPanel.Children.Add(new Label() {
Content = Guid.NewGuid().ToString()
});
}
your all set!
the implicit style defined for label will apply to all Label-instances defined under the scope of MainWindow. this can sure lead to side effects, cause every label instance, that does not specifiy an alternate style be iteslf will have this behavior. In this case you could consider defining the style in a more decent element, like the StackPanel i used...or just assign a x:Key to the style and assign it when you create the label instance in codebehind:
<Style
x:Key="zoomLabelStyle"
TargetType="Label">
...
</Style>
private void Button_Click(object sender, RoutedEventArgs e) {
_stackPanel.Children.Add(new Label() {
Content = Guid.NewGuid().ToString(),
Style=(Style)TryFindResource("zoomLabelStyle")
});
}