Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #309 from microsoft/animationcompleted
Browse files Browse the repository at this point in the history
Adding AnimationCompleted API Reference sample
  • Loading branch information
clarkezone authored Dec 6, 2019
2 parents 1b2a428 + c02ab38 commit 044d27c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions SampleGallery/SampleGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<DependentUpon>SampleGalleryPivotHost.xaml</DependentUpon>
</Compile>
<Compile Include="SampleGalleryUIIndirector.cs" />
<Compile Include="Samples\SDK 10586\AnimationCompleted\AnimationCompleted.xaml.cs">
<DependentUpon>AnimationCompleted.xaml</DependentUpon>
</Compile>
<Compile Include="Samples\SDK 15063\PullToRefresh\PullToRefresh.xaml.cs" Condition="$(TargetPlatformBuild) &gt;14393" />
<Compile Include="Samples\SDK 15063\ShowHideImplicitWebview\ShowHideImplicitWebview.xaml.cs" Condition="$(TargetPlatformBuild) &gt;14393" />
<Compile Include="Samples\SDK 15063\LightInterop\AmbLight.cs" Condition="$(TargetPlatformBuild) &gt;14393" />
Expand Down Expand Up @@ -333,6 +336,7 @@
<Content Include="Assets\Nature\Nature-7.jpg" />
<Content Include="Assets\NormalMapsAndMasks\bubblenm.jpg" />
<Content Include="Assets\SampleThumbnails\AdvancedShadows.PNG" />
<Content Include="Assets\SampleThumbnails\AnimationCompleted.PNG" />
<Content Include="Assets\SampleThumbnails\AnimationController.PNG" />
<Content Include="Assets\SampleThumbnails\BackDropControlSample.PNG" />
<Content Include="Assets\SampleThumbnails\BasicLayoutAndTransitions.PNG" />
Expand Down Expand Up @@ -465,6 +469,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\SDK 10586\AnimationCompleted\AnimationCompleted.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Samples\SDK 15063\PullToRefresh\PullToRefresh.xaml" Condition="$(TargetPlatformBuild) &gt;14393">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<local:SamplePage
x:Class="CompositionSampleGallery.AnimationCompleted"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CompositionSampleGallery"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="MainGrid">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
<Button x:Name="ShowButton" Content="Show Content" Click="ShowButton_Click"/>
<Button x:Name="HideButton" Content="Hide Content" Click="HideButton_Click"/>
</StackPanel>
</Grid>
</local:SamplePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************

using System;
using System.Linq;
using System.Numerics;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Hosting;

namespace CompositionSampleGallery
{
public sealed partial class AnimationCompleted : SamplePage
{
private SpriteVisual _visual;
private CompositionColorBrush _brush;
private Compositor _compositor;
private ScalarKeyFrameAnimation _showAnimation;
private ScalarKeyFrameAnimation _hideAnimation;
private CompositionScopedBatch _batch;
private bool _isHidden;

public AnimationCompleted()
{
this.InitializeComponent();
Setup();
}

public static string StaticSampleName => "Animation Completed";
public override string SampleName => StaticSampleName;
public static string StaticSampleDescription => "This sample demonstrates how to get a notification and clean up resources when a CompositionAnimation completes";
public override string SampleDescription => StaticSampleDescription;
public override string SampleCodeUri => "http://go.microsoft.com/fwlink/p/?LinkID=761160";

private void Setup()
{
var gridVisual = ElementCompositionPreview.GetElementVisual(MainGrid);
_compositor = gridVisual.Compositor;

_showAnimation = _compositor.CreateScalarKeyFrameAnimation();
_showAnimation.InsertKeyFrame(1.0f, 1.0f);
_showAnimation.Duration = TimeSpan.FromSeconds(1);

_hideAnimation = _compositor.CreateScalarKeyFrameAnimation();
_hideAnimation.InsertKeyFrame(1.0f, 0.0f);
_hideAnimation.Duration = TimeSpan.FromSeconds(1);

_isHidden = false;

CreateVisualTree();
}
private void CreateVisualTree()
{
_visual = _compositor.CreateSpriteVisual();
_visual.Size = new Vector2(300f);
_brush = _compositor.CreateColorBrush(Colors.Blue);
_visual.Brush = _brush;
ElementCompositionPreview.SetElementChildVisual(MainGrid, _visual);
}
private void ShowButton_Click(object sender, RoutedEventArgs e)
{
if (_isHidden)
{
CreateVisualTree();
_visual.Opacity = 0.0f;
_visual.StartAnimation("Opacity", _showAnimation);
_isHidden = false;
}
}

private void HideButton_Click(object sender, RoutedEventArgs e)
{
if (!_isHidden)
{
_batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
_batch.Completed += OnBatchCompleted;
_visual.StartAnimation("Opacity", _hideAnimation);
_batch.End();
_isHidden = true;
}
}
private void OnBatchCompleted(object sender, CompositionBatchCompletedEventArgs args)
{
_visual.Dispose();
_brush.Dispose();
_visual = null;
_brush = null;
}
}
}
3 changes: 2 additions & 1 deletion SampleGallery/Shared/SampleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ where MainPage.RuntimeCapabilities.AllSupportedSdkVersions.Contains(sampleDef.SD
new SampleDefinition(ColorBloomTransition.StaticSampleName, typeof(ColorBloomTransition), SampleType.EndToEnd, SampleCategory.Motion, false, false, "ms-appx:///Assets/SampleThumbnails/ColorBloom.jpg", description: ColorBloomTransition.StaticSampleDescription),
new SampleDefinition(ColorSlideTransition.StaticSampleName, typeof(ColorSlideTransition), SampleType.EndToEnd, SampleCategory.Motion, false, false, "ms-appx:///Assets/SampleThumbnails/ColorSlide.png", description: ColorSlideTransition.StaticSampleDescription),
new SampleDefinition(FlipToReveal.StaticSampleName, typeof(FlipToReveal), SampleType.EndToEnd, SampleCategory.Depth, false, false, "ms-appx:///Assets/SampleThumbnails/FlipToReveal.png", description: FlipToReveal.StaticSampleDescription),
new SampleDefinition(ConnectedAnimationShell.StaticSampleName, typeof(ConnectedAnimationShell), SampleType.EndToEnd, SampleCategory.Motion, false, false, "ms-appx:///Assets/SampleThumbnails/ContinuityAnimations.jpg", description: ConnectedAnimationShell.StaticSampleDescription, featured: true, tags: new string[1]{"ExpressionBuilder"}),
new SampleDefinition(ConnectedAnimationShell.StaticSampleName, typeof(ConnectedAnimationShell), SampleType.EndToEnd, SampleCategory.Motion, false, false, "ms-appx:///Assets/SampleThumbnails/ContinuityAnimations.jpg", description: ConnectedAnimationShell.StaticSampleDescription, featured: true, tags: new string[1]{"ExpressionBuilder"}),
new SampleDefinition(AnimationCompleted.StaticSampleName, typeof(AnimationCompleted), SampleType.Reference, SampleCategory.APIReference, false, false, "ms-appx:///Assets/SampleThumbnails/AnimationCompleted.png", description: AnimationCompleted.StaticSampleDescription),
#endif

#if SDKVERSION_14393
Expand Down

0 comments on commit 044d27c

Please # to comment.