0

What animation class would allow me to change the Visibility (not opacity) of a Grid object with a Storyboard instance in code (not XAML)?

So that I can set the to, from, and duration properties before adding it to the storyboard.

John
  • 5,942
  • 3
  • 42
  • 79
  • [ObjectAnimationUsingKeyFrames](https://msdn.microsoft.com/en-us/library/system.windows.media.animation.objectanimationusingkeyframes(v=vs.110).aspx) – Clemens Oct 20 '16 at 16:01

2 Answers2

0

You can use an ObjectAnimationUsingKeyFrames with some DiscreteObjectKeyFrame.

You can find an example here. The only work to do is translating that to C# code. (Which shouldn't be a huge problem.)

Community
  • 1
  • 1
haindl
  • 3,111
  • 2
  • 25
  • 31
0

This is the code necessary to animate the visibility.

    DiscreteObjectKeyFrame dk;

    ObjectAnimationUsingKeyFrames ok;

    ok = new ObjectAnimationUsingKeyFrames();
    dk = new DiscreteObjectKeyFrame();

    Storyboard.SetTarget(ok, myGrid);
    Storyboard.SetTargetProperty(ok, new PropertyPath(Grid.VisibilityProperty));
    dk.KeyTime = TimeSpan.FromSeconds(0.1);
    dk.Value = Visibility.Hidden;
    ok.KeyFrames.Add(dk);

    sb.Children.Add(ok);
John
  • 5,942
  • 3
  • 42
  • 79