<Window.Resources> <Storyboard x:Key="OnMouseEnter1"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="GridAnimace"> <EasingDoubleKeyFrame KeyTime="0:0:1" Value="180"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="OnMouseLeave1"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="GridAnimace"> <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </Window.Resources> <Window.Triggers> <EventTrigger RoutedEvent="UIElement.MouseEnter" SourceName="GridAnimace"> <BeginStoryboard Storyboard="{StaticResource OnMouseEnter1}"/> </EventTrigger> <EventTrigger RoutedEvent="UIElement.MouseLeave" SourceName="GridAnimace"> <BeginStoryboard x:Name="OnMouseLeave1_BeginStoryboard" Storyboard="{StaticResource OnMouseLeave1}"/> </EventTrigger> </Window.Triggers> <Grid x:Name="GridAnimace" HorizontalAlignment="Left" Height="458.92" VerticalAlignment="Top" Width="246" Margin="0,30.54,0,0" RenderTransformOrigin="0.5,0.5" Background="#FF1DB2A4"> <Grid.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="180"/> <TranslateTransform/> </TransformGroup> </Grid.RenderTransform> </Grid>
using System.Windows.Media.Animation; .... private void GridAnimace1_MouseEnter(object sender, MouseEventArgs e) { DoubleAnimation Animation = new DoubleAnimation { To = 0, Duration = TimeSpan.FromSeconds(1) }; GridAnimace1.BeginAnimation(Grid.WidthProperty, Animation); GridAnimace1.BeginAnimation(Grid.HeightProperty, Animation); } private void GridAnimace1_MouseLeave(object sender, MouseEventArgs e) { DoubleAnimation Animation = new DoubleAnimation { To = 227, Duration = TimeSpan.FromSeconds(1) }; GridAnimace1.BeginAnimation(Grid.WidthProperty, Animation); DoubleAnimation Animation1 = new DoubleAnimation { To = 458, Duration = TimeSpan.FromSeconds(1) }; GridAnimace1.BeginAnimation(Grid.HeightProperty, Animation1); }Nastaví se konečná hodnota (To) a doba trvání (Duration).
Pro posun objektu.
using System.Windows.Media.Animation; .... ThicknessAnimation translateAnimation = new ThicknessAnimation { }; translateAnimation.Duration = TimeSpan.FromSeconds(1); translateAnimation.To = new Thickness(1000, 1000, 0, 0); p[0].BeginAnimation(Image.MarginProperty, translateAnimation);
Pro rotaci objektu:
using Point = System.Windows.Point;
.....
DoubleAnimation rotaceAnimation = new DoubleAnimation()
{
From = 0,
To = 360,
Duration = TimeSpan.FromSeconds(1)
};
RotateTransform rt = new RotateTransform();
p[pocitacRozdavani].RenderTransform = rt;
p[pocitacRozdavani].RenderTransformOrigin = new Point(0.5, 0.5); //Střed otáčení.
rt.BeginAnimation(RotateTransform.AngleProperty, rotaceAnimation);