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

Commit 044d27c

Browse files
authored
Merge pull request #309 from microsoft/animationcompleted
Adding AnimationCompleted API Reference sample
2 parents 1b2a428 + c02ab38 commit 044d27c

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed
10.8 KB
Loading

SampleGallery/SampleGallery.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<DependentUpon>SampleGalleryPivotHost.xaml</DependentUpon>
118118
</Compile>
119119
<Compile Include="SampleGalleryUIIndirector.cs" />
120+
<Compile Include="Samples\SDK 10586\AnimationCompleted\AnimationCompleted.xaml.cs">
121+
<DependentUpon>AnimationCompleted.xaml</DependentUpon>
122+
</Compile>
120123
<Compile Include="Samples\SDK 15063\PullToRefresh\PullToRefresh.xaml.cs" Condition="$(TargetPlatformBuild) &gt;14393" />
121124
<Compile Include="Samples\SDK 15063\ShowHideImplicitWebview\ShowHideImplicitWebview.xaml.cs" Condition="$(TargetPlatformBuild) &gt;14393" />
122125
<Compile Include="Samples\SDK 15063\LightInterop\AmbLight.cs" Condition="$(TargetPlatformBuild) &gt;14393" />
@@ -333,6 +336,7 @@
333336
<Content Include="Assets\Nature\Nature-7.jpg" />
334337
<Content Include="Assets\NormalMapsAndMasks\bubblenm.jpg" />
335338
<Content Include="Assets\SampleThumbnails\AdvancedShadows.PNG" />
339+
<Content Include="Assets\SampleThumbnails\AnimationCompleted.PNG" />
336340
<Content Include="Assets\SampleThumbnails\AnimationController.PNG" />
337341
<Content Include="Assets\SampleThumbnails\BackDropControlSample.PNG" />
338342
<Content Include="Assets\SampleThumbnails\BasicLayoutAndTransitions.PNG" />
@@ -465,6 +469,10 @@
465469
<SubType>Designer</SubType>
466470
<Generator>MSBuild:Compile</Generator>
467471
</Page>
472+
<Page Include="Samples\SDK 10586\AnimationCompleted\AnimationCompleted.xaml">
473+
<SubType>Designer</SubType>
474+
<Generator>MSBuild:Compile</Generator>
475+
</Page>
468476
<Page Include="Samples\SDK 15063\PullToRefresh\PullToRefresh.xaml" Condition="$(TargetPlatformBuild) &gt;14393">
469477
<Generator>MSBuild:Compile</Generator>
470478
<SubType>Designer</SubType>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<local:SamplePage
2+
x:Class="CompositionSampleGallery.AnimationCompleted"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:CompositionSampleGallery"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
<Grid x:Name="MainGrid">
10+
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
11+
<Button x:Name="ShowButton" Content="Show Content" Click="ShowButton_Click"/>
12+
<Button x:Name="HideButton" Content="Hide Content" Click="HideButton_Click"/>
13+
</StackPanel>
14+
</Grid>
15+
</local:SamplePage>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
using System;
16+
using System.Linq;
17+
using System.Numerics;
18+
using Windows.UI;
19+
using Windows.UI.Composition;
20+
using Windows.UI.Xaml;
21+
using Windows.UI.Xaml.Hosting;
22+
23+
namespace CompositionSampleGallery
24+
{
25+
public sealed partial class AnimationCompleted : SamplePage
26+
{
27+
private SpriteVisual _visual;
28+
private CompositionColorBrush _brush;
29+
private Compositor _compositor;
30+
private ScalarKeyFrameAnimation _showAnimation;
31+
private ScalarKeyFrameAnimation _hideAnimation;
32+
private CompositionScopedBatch _batch;
33+
private bool _isHidden;
34+
35+
public AnimationCompleted()
36+
{
37+
this.InitializeComponent();
38+
Setup();
39+
}
40+
41+
public static string StaticSampleName => "Animation Completed";
42+
public override string SampleName => StaticSampleName;
43+
public static string StaticSampleDescription => "This sample demonstrates how to get a notification and clean up resources when a CompositionAnimation completes";
44+
public override string SampleDescription => StaticSampleDescription;
45+
public override string SampleCodeUri => "http://go.microsoft.com/fwlink/p/?LinkID=761160";
46+
47+
private void Setup()
48+
{
49+
var gridVisual = ElementCompositionPreview.GetElementVisual(MainGrid);
50+
_compositor = gridVisual.Compositor;
51+
52+
_showAnimation = _compositor.CreateScalarKeyFrameAnimation();
53+
_showAnimation.InsertKeyFrame(1.0f, 1.0f);
54+
_showAnimation.Duration = TimeSpan.FromSeconds(1);
55+
56+
_hideAnimation = _compositor.CreateScalarKeyFrameAnimation();
57+
_hideAnimation.InsertKeyFrame(1.0f, 0.0f);
58+
_hideAnimation.Duration = TimeSpan.FromSeconds(1);
59+
60+
_isHidden = false;
61+
62+
CreateVisualTree();
63+
}
64+
private void CreateVisualTree()
65+
{
66+
_visual = _compositor.CreateSpriteVisual();
67+
_visual.Size = new Vector2(300f);
68+
_brush = _compositor.CreateColorBrush(Colors.Blue);
69+
_visual.Brush = _brush;
70+
ElementCompositionPreview.SetElementChildVisual(MainGrid, _visual);
71+
}
72+
private void ShowButton_Click(object sender, RoutedEventArgs e)
73+
{
74+
if (_isHidden)
75+
{
76+
CreateVisualTree();
77+
_visual.Opacity = 0.0f;
78+
_visual.StartAnimation("Opacity", _showAnimation);
79+
_isHidden = false;
80+
}
81+
}
82+
83+
private void HideButton_Click(object sender, RoutedEventArgs e)
84+
{
85+
if (!_isHidden)
86+
{
87+
_batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
88+
_batch.Completed += OnBatchCompleted;
89+
_visual.StartAnimation("Opacity", _hideAnimation);
90+
_batch.End();
91+
_isHidden = true;
92+
}
93+
}
94+
private void OnBatchCompleted(object sender, CompositionBatchCompletedEventArgs args)
95+
{
96+
_visual.Dispose();
97+
_brush.Dispose();
98+
_visual = null;
99+
_brush = null;
100+
}
101+
}
102+
}

SampleGallery/Shared/SampleDefinition.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ where MainPage.RuntimeCapabilities.AllSupportedSdkVersions.Contains(sampleDef.SD
134134
new SampleDefinition(ColorBloomTransition.StaticSampleName, typeof(ColorBloomTransition), SampleType.EndToEnd, SampleCategory.Motion, false, false, "ms-appx:///Assets/SampleThumbnails/ColorBloom.jpg", description: ColorBloomTransition.StaticSampleDescription),
135135
new SampleDefinition(ColorSlideTransition.StaticSampleName, typeof(ColorSlideTransition), SampleType.EndToEnd, SampleCategory.Motion, false, false, "ms-appx:///Assets/SampleThumbnails/ColorSlide.png", description: ColorSlideTransition.StaticSampleDescription),
136136
new SampleDefinition(FlipToReveal.StaticSampleName, typeof(FlipToReveal), SampleType.EndToEnd, SampleCategory.Depth, false, false, "ms-appx:///Assets/SampleThumbnails/FlipToReveal.png", description: FlipToReveal.StaticSampleDescription),
137-
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"}),
137+
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"}),
138+
new SampleDefinition(AnimationCompleted.StaticSampleName, typeof(AnimationCompleted), SampleType.Reference, SampleCategory.APIReference, false, false, "ms-appx:///Assets/SampleThumbnails/AnimationCompleted.png", description: AnimationCompleted.StaticSampleDescription),
138139
#endif
139140

140141
#if SDKVERSION_14393

0 commit comments

Comments
 (0)