Begin a storyboard when hovering an Image - wpf

I have a simple image on my form. What I would like to do is when I hover the image it starts a storyboard which basically does a 360 loop on itself.
Here's the storyboard, it's called TurnLogo:
<Storyboard x:Key="TurnLogo">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="360"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
Here's my image :
<Image x:Name="image" HorizontalAlignment="Left" Height="64" VerticalAlignment="Top" Width="64" Source="Images/Logo/Logomakr_3lb9fd.png" Margin="7,7,0,0" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
<Image.Style>
<Style>
<Style.Triggers>
<EventTrigger RoutedEvent="Control.MouseEnter">
<BeginStoryboard Storyboard="{StaticResource TurnLogo}"/>
</EventTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
When I hover the image it fails.. Why ?

Remove the Storyboard.TargetName:
<Storyboard x:Key="TurnLogo">
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle"
By="360" Duration="0:0:1"/>
</Storyboard>
and simplify the RenderTransform:
<Image ... RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<RotateTransform/>
</Image.RenderTransform>
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard Storyboard="{StaticResource TurnLogo}"/>
</EventTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>

Related

WPF Icon to spin

based on this answer i have two questions:
Whats the name of the marked icon?
How can I make it to raotate to the other direction, i.e to spin like:
Itried to add FlowDirection="RightToLeft" like:
<fa:ImageAwesome FlowDirection="RightToLeft" SpinDuration="6" Icon="Cog" Width="200" Height="200" Foreground="White" Spin="True" />
but it still rotate to same direction
this should do the trick for you:
<Viewbox Height="20">
<Path Fill="black" Data="M28,2.202v4.059C37.053,7.706,44,15.547,44,25c0,10.477-8.523,19-19,19S6,35.477,6,25c0-9.442,6.93-17.275,15.966-18.734 V2.206C10.713,3.696,2,13.347,2,25c0,12.682,10.317,23,23,23s23-10.318,23-23C48,13.335,39.269,3.677,28,2.202z" RenderTransformOrigin="0.5,0.5" >
<Path.RenderTransform>
<RotateTransform/>
</Path.RenderTransform>
<Path.Style>
<Style>
<Style.Triggers>
<Trigger Property="Image.IsEnabled" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="RenderTransform.Angle"
From="0"
To="360"
Duration="0:0:1"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</Viewbox>

Rotation animation slows down my WPF interface

I have a button with a style.
That style has an image:
<ContentPresenter.Content>
<Grid>
.
.
.
<Image x:Name="RecordingImage"
Source="/Studio;component/Images/Icons/image.png"
Width="107"
Height="107"
RenderTransformOrigin=".5,.5"
Visibility="Hidden">
<Image.RenderTransform>
<RotateTransform Angle="0" />
</Image.RenderTransform>
</Image>
And is animated with this code:
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="RecordingImage" Property="Visibility" Value="Visible" />
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="RecordingImage"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
From="0" To="360" Duration="00:00:03.000" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
But when the animation begins, all my interface slows down.
What is the problem?

Animation border

I have border, that I want to animate by clicking button (name = "button1"). Button is outside. My code throws an exception. Whats wrong? Thanks
<Border Name="brdClasses" Background="#FF2c3e50">
<Border.RenderTransform>
<ScaleTransform x:Name="MyAnimatedScaleTransform"
ScaleX="1" ScaleY="1" />
</Border.RenderTransform>
<Border.Triggers>
<EventTrigger SourceName="button1" RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard Name="MyBeginStoryboard">
<Storyboard >
<DoubleAnimation
Storyboard.TargetName="MyAnimatedScaleTransform"
Storyboard.TargetProperty="(ScaleTransform.ScaleX)"
To="3.0" Duration="0:0:10" AutoReverse="True" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Border.Triggers>
</Border>
I Dont know why your code doent works... But I did a simple example in a specific way.. if it helps make use of that..
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Name="brdClasses" Grid.Row="1" Background="#FF2c3e50" Height="100" Width="150">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
</Border>
<Button Content="Button1" x:Name="button1">
<Button.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button1">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="brdClasses">
<EasingDoubleKeyFrame KeyTime="0" Value="3"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>

How to animate different buttons one by one with same animation, WPF

I'm new to WPF and have a probably stupid question.
I'm trying to animate 4 buttons with the same animation (rotate 360 degrees) when one of them is clicked and only this one gets animated.
Here is what I have so far:
<Window.Resources>
<Storyboard x:Key="Storyboard" BeginTime="00:00:00" Duration="00:00:10">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="rotButton" Storyboard.TargetProperty="(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="0:0:00.0" Value="0.0" />
<SplineDoubleKeyFrame KeyTime="0:0:01.0" Value="360.0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
And rotButton is defined in the first button here:
<Button Click="Button_Click">
<StackPanel>
<Image Source="open.png" Height="46" Width="48" />
</StackPanel>
<Button.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotButton" Angle="0" CenterX="25" CenterY="25" />
<ScaleTransform x:Name="scaButton" ScaleX="1" ScaleY="1" CenterX="50" CenterY="25" />
</TransformGroup>
</Button.RenderTransform>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard Storyboard="{StaticResource Storyboard}" />
</EventTrigger>
</Button.Triggers>
</Button>
How can I use this code for all other buttons and have "common" Button.RenderTransform for every button? There should be a lot more smarter way of creating 3 more storyboards and using rotButton1, rotButton2, etc for each button.
I hope it makes sense and point me in the right direction :)
Thanks
If you create a style for your button, you can use a setter to set the RenderTransform for each instance of button that uses that Style. Also, styles can have triggers.
The trick is the right path syntax http://blogs.charteris.com/blogs/patl-closed/archive/2007/03/20/Complex-PropertyPath-syntax.aspx
<Window.Resources>
<TransformGroup x:Key="transformGroup">
<RotateTransform Angle="0" CenterX="25" CenterY="25" />
<ScaleTransform ScaleX="1" ScaleY="1" CenterX="50" CenterY="25" />
</TransformGroup>
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
<Setter Property="RenderTransform" Value="{StaticResource transformGroup}"/>
<Style.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard BeginTime="00:00:00" Duration="00:00:10">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Button.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="0:0:00.0" Value="0.0" />
<SplineDoubleKeyFrame KeyTime="0:0:01.0" Value="360.0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<Button Style="{StaticResource MyButtonStyle}"/>
<Button Style="{StaticResource MyButtonStyle}"/>
</StackPanel>
</Grid>

Animation for images wpf

I want to move the images one by one like slides. i am using the following code to move one image. How to apply this animation to all the images in the image folder.
Code:
<Image Name="img" Width="50" Height="25" Grid.Row="3" HorizontalAlignment="Left" Source="btn_audio_stop.jpg">
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Trans" Storyboard.TargetProperty="Y" Duration="0:0:25">
<LinearDoubleKeyFrame Value="350" KeyTime="0:0:25" />
<!--<LinearDoubleKeyFrame Value="50" KeyTime="0:0:5" />
<LinearDoubleKeyFrame Value="200" KeyTime="0:0:3" />-->
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
<Image.RenderTransform>
<TranslateTransform x:Name="Trans" X="0" Y="0" />
</Image.RenderTransform>
</Image>
See following articles
http://www.c-sharpcorner.com/UploadFile/prvn_131971/ImageSlideshowWPF11162008224421PM/ImageSlideshowWPF.aspx
http://www.c-sharpcorner.com/UploadFile/dpatra/569/

Resources