I need to make relatively simple WPF application.
Have storyboard that animates buttons when they are pressed, so that they fade out. Animation gradually reduces opacity and sets visibility to hidden. And it works perfectly.
Problem is when I want to show that button again, but programmatically. Well it doesn't work, properties changed by animation become imune to changes made from my code. I also need to hide button programmatically.
So I tried to make fade in animation and call it progammatically like this:
Storyboard fadein = ((Storyboard)FindResource("fadein"));
fadein.Begin(btnFlag);
I do same to call fadeout programmatically.
Now I have different problem:
The first time I call fadeout programmatically, it somehow prevents fadeout to be triggered again when button is pressed.
How should I do it? Thank you.
And I'm sorry if it's stupid question, I just need to make this WPF application and I have no experience with it.
EDIT: I have already tried to change FillBehavior, but it didn't help.
EDIT: I find this really strange. I set btnFlag.Opacity = 1; then immidiatelly after that line I have this line:
Console.WriteLine(btnFlag.Opacity);
and it prints 0.1, which is value set by animation.
EDIT:
This is my fadein and fadeout storyboards:
<Storyboard x:Key="fadein">
<DoubleAnimation BeginTime="0:0:0.0" Storyboard.TargetProperty="Opacity" From="0.1" To="1.0" Duration="0:0:0.1"/>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:0.0" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="fadeout">
<DoubleAnimation BeginTime="0:0:0.25" Storyboard.TargetProperty="Opacity" From="1.0" To="0.1" Duration="0:0:0.5"/>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:0.75" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Hidden</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
I have Style which is referenced by all buttons that I want to have same look and feel. And this is code snippet from that Style:
<BeginStoryboard Storyboard="{StaticResource fadeout}"/>
</Trigger.EnterActions>
It all works nice, but the first time I start animation programmatically it stops working the usual way. And if I want to modify properties in code, that were previously modified by animation, all modifications are ignored.
Storyboard.TargetName
– safi