I am trying to play a bit with the badged control from Mahapps. Is it possible to change the size of the badge (not just the color/value/etc..)
Finally I am trying to do some sort of bigger pulse effect when the badge value changed, I tried the following for the color but it didn't work:
<Controls:Badged.Triggers>
<EventTrigger RoutedEvent="Controls:Badged.BadgeChanged">
<EventTrigger.EnterActions>
<BeginStoryboard Name="AnimateVisibilityChanged">
<Storyboard>
<ColorAnimation Duration="0:0:0.5"
From="#FFEE4709"
To="Green"
BeginTime="0:0:0"
Storyboard.TargetProperty="(Controls:Badged.BadgeBackground).(SolidColorBrush.Color)">
</ColorAnimation>
<ColorAnimation Duration="0:0:0.5"
From="Green"
To="Transparent"
AutoReverse="True"
BeginTime="0:0:2"
RepeatBehavior="0:0:2.5"
Storyboard.TargetProperty="(Controls:Badged.BadgeBackground).(SolidColorBrush.Color)">
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.EnterActions>
<EventTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="AnimateVisibilityChanged" />
</EventTrigger.ExitActions>
</EventTrigger>
</Controls:Badged.Triggers>
The next step if this would work is to also increase the size more than it's already increasing
It looks like I will answer to my question:
the animation didn't work because I used EnterActions instead of simply Actions (EventTrigger.Actions)
To change the size of the badge when the value changes I had to use BadgeChangedStoryboard property and replace with my own:
<SineEase x:Key="BadgeEase"
EasingMode="EaseOut" />
<Storyboard x:Key="BadgeChangedStoryboard">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
<EasingDoubleKeyFrame KeyTime="0"
Value="2.3" />
<EasingDoubleKeyFrame EasingFunction="{StaticResource BadgeEase}"
KeyTime="0:0:0.3"
Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
<EasingDoubleKeyFrame KeyTime="0"
Value="2.3" />
<EasingDoubleKeyFrame EasingFunction="{StaticResource BadgeEase}"
KeyTime="0:0:0.3"
Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
To change the size change both the easing double key frame Value
Related
I have a textblock which should only show 2 lines of the text, while it is unselected. As soon as it gets selected, I want it to expand smoothly.
I started with something like:
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Second"
Storyboard.TargetProperty="(TextBlock.MaxHeight)"
To="50.0" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
But the issue here is, that I don't know how big the text is.
You should be able to use From='0' instead, which would start the animation with a value of 0 and end with whatever the value of MaxHeight is. However, that raises a different problem, as MaxHeight defaults to infinity, which would make the animation far too fast. Adding an ObjectAnimationUsingKeyframes at the start that sets MaxHeight to ActualHeight might work to resolve this. Something like this:
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyframes
Storyboard.TargetName='Second'
Storyboard.TargetProperty='(TextBlock.MaxHeight)'>
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{Binding TargetName=Second, Path=ActualHeight}" />
</ObjectAnimationUsingKeyframes>
<DoubleAnimation
Storyboard.TargetName="Second"
Storyboard.TargetProperty="(TextBlock.MaxHeight)"
From="0" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
You can use DoubleAnimation to implement this. I have implemented this in a sample application.
<Window.Resources>
<Storyboard x:Key="OnGotFocus">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="textBox" Storyboard.TargetProperty="(FrameworkElement.Height)">
<EasingDoubleKeyFrame KeyTime="0:0:2">
<EasingDoubleKeyFrame.Value>
<System:Double>NaN</System:Double>
</EasingDoubleKeyFrame.Value>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="OnLostFocus">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="textBox" Storyboard.TargetProperty="(FrameworkElement.Height)">
<EasingDoubleKeyFrame KeyTime="0">
<EasingDoubleKeyFrame.Value>
<System:Double>NaN</System:Double>
</EasingDoubleKeyFrame.Value>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="30" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="UIElement.GotFocus" SourceName="textBox">
<BeginStoryboard Storyboard="{StaticResource OnGotFocus}" />
</EventTrigger>
<EventTrigger RoutedEvent="UIElement.LostFocus" SourceName="textBox">
<BeginStoryboard x:Name="OnLostFocus_BeginStoryboard" Storyboard="{StaticResource OnLostFocus}" />
</EventTrigger>
</Window.Triggers>
Your code for textbox should be :
<TextBox x:Name="textBox"
Height="30"
HorizontalAlignment="Right"
Text="Hello World" />
This will animate the textbox to a specified height as soon as it gets focussed. I have added an animation to collapse it as well when it loses focus.
Hope this helps you.
I'm using the following animation to "flash" a control:
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="1"
To="0.3"
AutoReverse="True"
Duration="0:0:0.5"
RepeatBehavior="Forever" />
The resulting effect is more like a fade in and out. What I'm really after is to just "flip" the opacity from one value to the other (and back) every 0.5 seconds, rather than a smooth transition. How do I achieve that?
This is the solution you are looking for:
<Storyboard RepeatBehavior="Forever" Duration="0:0:0.5" AutoReverse="True">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity">
<DiscreteDoubleKeyFrame Value="0.3" KeyTime="0:0:0.25" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
You can adapt it to your needs.
I have a TextBlock In My Application. I want to TranslateTransform Animation each word In My
TextBlock. This would be similar to Text Effect's Exist In PowerPoint.
For example: each word would move 20px to up and then return to last position
In my research, I Found a sample From Microsoft that I used to see how I can make this Work.
First we define TextEffects For TextBlock:
<TextBlock.TextEffects>
<TextEffectCollection>
<TextEffect PositionCount="1" x:Name="TxtEffect">
<TextEffect.Transform>
<TranslateTransform x:Name="Transform" X="0" Y="0"></TranslateTransform>
</TextEffect.Transform>
</TextEffect>
</TextEffectCollection>
</TextBlock.TextEffects>
Second, we define the Animations:
1) Animation For Increase PositionCount With Int32AnimationUsingKeyFrames And Define's
Int32AnimationUsingKeyFrames.KeyFrames The Number Of Words Exist In Text
2) Animation For TranslateTransform To Move Each Word
Example For Three Words:
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetName="Transform" Storyboard.TargetProperty="Y" From="0" To="20" BeginTime="0:0:0" Duration="0:0:0.25"/>
<DoubleAnimation Storyboard.TargetName="Transform" Storyboard.TargetProperty="Y" From="20" To="-20" BeginTime="0:0:0.25" Duration="0:0:0.5" />
<DoubleAnimation Storyboard.TargetName="Transform" Storyboard.TargetProperty="Y" From="-20" To="0" BeginTime="0:0:0.75" Duration="0:0:0.25" />
</Storyboard>
</BeginStoryboard>
<BeginStoryboard Name="TxtEf">
<Storyboard>
<Int32AnimationUsingKeyFrames Storyboard.TargetName="TxtEffect"
Storyboard.TargetProperty="PositionStart"
Duration="0:0:2.5" AutoReverse="True" RepeatBehavior="Forever">
<Int32AnimationUsingKeyFrames.KeyFrames>
<DiscreteInt32KeyFrame Value="0" KeyTime="0:0:0" />
<DiscreteInt32KeyFrame Value="1" KeyTime="0:0:1" />
<DiscreteInt32KeyFrame Value="2" KeyTime="0:0:2" />
</Int32AnimationUsingKeyFrames.KeyFrames>
</Int32AnimationUsingKeyFrames>
</Storyboard>
The storyBoard_Completed event is invoked in a delay of about half a second after the visual animation had finished.
Would be glad for some more eyes to check out my Storyboard XAML:
<Storyboard x:Key="blaAnimation" Completed="storyBoard_Completed">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="bla1" Storyboard.TargetProperty="Offset" Completed="bla_Completed">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" x:Name="bla1StartKeyFrame"/>
<EasingDoubleKeyFrame Value="-10.2" KeyTime="0:0:1">
<EasingDoubleKeyFrame.EasingFunction>
<PowerEase EasingMode="EaseIn"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="-20" x:Name="bla1Animation">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase EasingMode="EaseOut" Oscillations="5" Springiness="20"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="bla2" Storyboard.TargetProperty="Offset" BeginTime="0:0:0.1" Completed="bla2_Completed">
<DiscreteDoubleKeyFrame Value="0" KeyTime="0:0:0.1" x:Name="bla2StartKeyFrame"/>
<EasingDoubleKeyFrame Value="-10.2" KeyTime="0:0:1.1">
<EasingDoubleKeyFrame.EasingFunction>
<PowerEase EasingMode="EaseIn"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:2.1" Value="-20" x:Name="bla2Animation">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase EasingMode="EaseOut" Oscillations="5" Springiness="20"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="bla3" Storyboard.TargetProperty="Offset" BeginTime="0:0:0.18" Completed="bla3_Completed">
<DiscreteDoubleKeyFrame Value="0" KeyTime="0:0:0.2" x:Name="bla3StartKeyFrame"/>
<EasingDoubleKeyFrame Value="-10.2" KeyTime="0:0:1.2">
<EasingDoubleKeyFrame.EasingFunction>
<PowerEase EasingMode="EaseIn"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:2.2" Value="-20" x:Name="bla3Animation">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase EasingMode="EaseOut" Oscillations="5" Springiness="20"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
Thanks in advance,
--Ran.
When in doubt - Blend it
Following on from comment trail (above), the end result is "If you have access to it (or can afford it), always use Expression Blend for creating animation storyboards".
Blend is the best way to learn animation which can get very complex quite easily. Blend also optimises certainly animations automatically for you.
As you know there is no support at all in VS 2010 for authoring animation, except with XAML, and that is error prone. It is also very hard to visualise multiple animations in your head with only text to go by :)
In my current application I have this little animation. It makes a full 360 degrees rotation of a canvas and works fine.
<DoubleAnimation
Storyboard.TargetName="WaitCanvas"
Storyboard.TargetProperty="(Canvas.RenderTransform).(TransformGroup.Children)[0]
.(RotateTransform.Angle)"
From="0" To="360" Duration="0:0:2"
AutoReverse="False" RepeatBehavior="Forever" />
But the thing I want to do is not a smooth animation but animation is steps of 22.5 degrees each. How can this be done?
You could use a DoubleAnimationUsingKeyFrames and make two keyframes for each increment of 22.5 degrees at the same point in time.
Adding the XAML example which I was actually searching for.
<Storyboard
BeginTime="00:00:00"
RepeatBehavior="Forever"
Storyboard.TargetName="WaitCanvas"
Storyboard.TargetProperty="(Canvas.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)">
<DoubleAnimationUsingKeyFrames Duration="0:0:2">
<DoubleKeyFrameCollection>
<DiscreteDoubleKeyFrame KeyTime="0:0:0.000" Value="0" />
<DiscreteDoubleKeyFrame KeyTime="0:0:0.125" Value="22.5" />
<DiscreteDoubleKeyFrame KeyTime="0:0:0.250" Value="45" />
<DiscreteDoubleKeyFrame KeyTime="0:0:0.375" Value="67.5" />
<DiscreteDoubleKeyFrame KeyTime="0:0:0.500" Value="90" />
<DiscreteDoubleKeyFrame KeyTime="0:0:0.625" Value="110.5" />
<!-- ... -->
</DoubleKeyFrameCollection>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
Even easier, use the DoubleAnimation "By" property, as in:
<DoubleAnimation
Storyboard.TargetName="WaitCanvas"
Storyboard.TargetProperty="(Canvas.RenderTransform).(TransformGroup.Children)[0]
.(RotateTransform.Angle)"
From="0" To="360" By="22.5" Duration="0:0:2"
AutoReverse="False" RepeatBehavior="Forever" />