I'm trying to create implicit show and hide animations for UIElements in code that can be dynamically added and removed from the visual tree. I've tried the following:
private void testButton_Tapped(object sender, TappedRoutedEventArgs e)
{
var myImage = new Image();
myImage.Source = new BitmapImage(new Uri("https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png"));
var visual = ElementCompositionPreview.GetElementVisual(myImage);
var animation = visual.Compositor.CreateVector3KeyFrameAnimation();
var easing = visual.Compositor.CreateLinearEasingFunction();
animation.InsertKeyFrame(0f, new Vector3(1200f, 0f, 0f), easing);
ElementCompositionPreview.SetImplicitShowAnimation(myImage, animation);
TestGrid.Children.Add(myImage);
}
... and the app and debugger crash with an unhandled exception. Stepping through code the crash happens just as soon as I step past the closing brace of the method. Also note I've tried the same code but using all global variables so I don't think it's the GC.