Skip to content

Instantly share code, notes, and snippets.

@dupuyjs
Created March 6, 2016 18:03
Show Gist options
  • Save dupuyjs/6a3ad242832493b73c66 to your computer and use it in GitHub Desktop.
Save dupuyjs/6a3ad242832493b73c66 to your computer and use it in GitHub Desktop.
Visual Layer - ElementCompositionPreview
using System;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
namespace XamlComposition
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
Visual visual = ElementCompositionPreview.GetElementVisual(image);
Compositor compositor = visual.Compositor;
ScalarKeyFrameAnimation animation = compositor.CreateScalarKeyFrameAnimation();
animation.InsertKeyFrame(0.0f, 0.0f); // Optional
animation.InsertKeyFrame(1.0f, 1.0f, compositor.CreateLinearEasingFunction());
animation.Duration = TimeSpan.FromSeconds(3);
animation.IterationBehavior = AnimationIterationBehavior.Forever;
visual.StartAnimation("Opacity", animation);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment