I'm trying to create an animated control which changes opacity based on cue (pressing space).
The animation itself works properly. Based on the keypress, the opacity animates and the control comes into view. I put the animation on a grid control which contains the rest of the content.
The problem is this: After the animation finishes, the IsEnabled property of the grid remains "false", even after I manually (from code-behind) set it to true. That command doesn't raise an exception, but doesn't actually change the property either.
When I then run the same animation again, but reverse, the value actually does become "true". But of course, at that moment it is already fading out.
void Initialize()
{
// fade animation storyboard
FadeAnimation = new DoubleAnimation(0.0, 1.0,
new Duration(TimeSpan.FromSeconds(0.7)))
{ FillBehavior = FillBehavior.HoldEnd };
FadeStoryboard.Children.Add(FadeAnimation);
Storyboard.SetTargetName(FadeAnimation, grid.Name);
Storyboard.SetTargetProperty(FadeAnimation,
new PropertyPath(Grid.OpacityProperty));
}
// flipping the animation around
void InputManager_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
{
if (!ViewModel.IsActive)
{
FadeAnimation.From = grid.Opacity;
FadeAnimation.To = 1.0;
FadeStoryboard.Begin(this);
ViewModel.IsActive = true;
}
else if (ViewModel.IsActive)
{
FadeAnimation.From = grid.Opacity;
FadeAnimation.To = 0.0;
FadeStoryboard.Begin(this);
ViewModel.IsActive = false;
}
}
}
[Edit] Through some additional debugging I've found that it's the animation that actively sets enabled to false on fade-in, and sets it to true when it fades out, which is the exact opposite of what I want it to do.
[Edit 2] I'm getting the exact same problem when I ditch the animation altogether, and simply change the visibility to and from Hidden. It enables when I make it Hidden, and disables when I make it Visible.