├── Properties
├── Microsoft.Windows.Toolkit.UI.Animations.rd.xml
└── AssemblyInfo.cs
├── project.json
├── Microsoft.Toolkit.Uwp.UI.Animations.csproj.DotSettings
├── AnimationSetCompletedEventArgs.cs
├── Behaviors
├── CompositionBehaviorBase.nongeneric.cs
├── Blur.cs
├── CompositionBehaviorBase.cs
└── BehaviorBase.cs
├── AnimationSetState.cs
├── EffectAnimationDefinition.cs
├── EffectDirectPropertyChangeDefinition.cs
├── AnimationTask.cs
├── Extensions
├── AnimationTools.cs
├── AnimationExtensions.Blur.cs
└── AnimationExtensions.cs
├── .gitattributes
├── Effects
├── Blur.cs
└── AnimationEffect.cs
├── EasingType.cs
├── README.md
├── Microsoft.Toolkit.Uwp.UI.Animations.ruleset
├── .gitignore
├── SurfaceLoader.cs
├── Mika.Toolkit.Uwp.UI.Animations.csproj
└── AnimationSet.cs
/Properties/Microsoft.Windows.Toolkit.UI.Animations.rd.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "Microsoft.NETCore.UniversalWindowsPlatform": "5.3.2",
4 | "Microsoft.Xaml.Behaviors.Uwp.Managed": "2.0.0",
5 | "Win2D.uwp": "1.20.0"
6 | },
7 | "frameworks": {
8 | "uap10.0": {}
9 | },
10 | "runtimes": {
11 | "win10-arm": {},
12 | "win10-arm-aot": {},
13 | "win10-x86": {},
14 | "win10-x86-aot": {},
15 | "win10-x64": {},
16 | "win10-x64-aot": {}
17 | }
18 | }
--------------------------------------------------------------------------------
/Microsoft.Toolkit.Uwp.UI.Animations.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
--------------------------------------------------------------------------------
/AnimationSetCompletedEventArgs.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using System;
14 |
15 | namespace Microsoft.Toolkit.Uwp.UI.Animations
16 | {
17 | ///
18 | /// AnimationSet Completed EventArgs.
19 | ///
20 | public class AnimationSetCompletedEventArgs : EventArgs
21 | {
22 | ///
23 | /// Gets a value indicating whether the animation completed
24 | ///
25 | public bool Completed { get; internal set; }
26 | }
27 | }
--------------------------------------------------------------------------------
/Behaviors/CompositionBehaviorBase.nongeneric.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Windows.UI.Xaml;
14 |
15 | namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
16 | {
17 | ///
18 | /// Non-generic convenience implementation to provide backwards compatibility.
19 | ///
20 | ///
21 | public abstract class CompositionBehaviorBase : CompositionBehaviorBase
22 | {
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/AnimationSetState.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | namespace Microsoft.Toolkit.Uwp.UI.Animations
14 | {
15 | ///
16 | /// States of AnimationSet.
17 | ///
18 | public enum AnimationSetState
19 | {
20 | ///
21 | /// The animation has not been started
22 | ///
23 | NotStarted,
24 |
25 | ///
26 | /// The animation has been started and is in progress
27 | ///
28 | Running,
29 |
30 | ///
31 | /// The animation has been started and is stopped
32 | ///
33 | Stopped,
34 |
35 | ///
36 | /// The animation had completed
37 | ///
38 | Completed
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/EffectAnimationDefinition.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Windows.UI.Composition;
14 |
15 | namespace Microsoft.Toolkit.Uwp.UI.Animations
16 | {
17 | ///
18 | /// Defines an which is used by
19 | /// to link effect animations to Visuals
20 | ///
21 | internal class EffectAnimationDefinition
22 | {
23 | ///
24 | /// Gets or sets that will be animated
25 | ///
26 | public CompositionObject EffectBrush { get; set; }
27 |
28 | ///
29 | /// Gets or sets the
30 | ///
31 | public CompositionAnimation Animation { get; set; }
32 |
33 | ///
34 | /// Gets or sets the property name that will be animated on the
35 | ///
36 | public string PropertyName { get; set; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/EffectDirectPropertyChangeDefinition.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Windows.UI.Composition;
14 |
15 | namespace Microsoft.Toolkit.Uwp.UI.Animations
16 | {
17 | ///
18 | /// Defines an which is used by
19 | /// to link effect property Changes to Visuals
20 | ///
21 | internal class EffectDirectPropertyChangeDefinition
22 | {
23 | ///
24 | /// Gets or sets that will be animated
25 | ///
26 | public CompositionObject EffectBrush { get; set; }
27 |
28 | ///
29 | /// Gets or sets the value for the property
30 | ///
31 | public float Value { get; set; }
32 |
33 | ///
34 | /// Gets or sets the property name that will be animated on the
35 | ///
36 | public string PropertyName { get; set; }
37 | }
38 | }
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using System.Reflection;
14 | using System.Runtime.InteropServices;
15 |
16 | // General Information about an assembly is controlled through the following
17 | // set of attributes. Change these attribute values to modify the information
18 | // associated with an assembly.
19 | [assembly: AssemblyTitle("Mika.Toolkit.Uwp.UI.Animations")]
20 | [assembly: AssemblyDescription("")]
21 | [assembly: AssemblyConfiguration("")]
22 | [assembly: AssemblyCompany("")]
23 | [assembly: AssemblyProduct("Mika.Toolkit.Uwp.UI.Animations")]
24 | [assembly: AssemblyCopyright("Copyright © 2017")]
25 | [assembly: AssemblyTrademark("")]
26 | [assembly: AssemblyCulture("")]
27 |
28 | // Version information for an assembly consists of the following four values:
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("0.5.0.0")]
37 | [assembly: AssemblyFileVersion("0.5.0.0")]
38 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/AnimationTask.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using System;
14 | using System.Threading.Tasks;
15 |
16 | namespace Microsoft.Toolkit.Uwp.UI.Animations
17 | {
18 | ///
19 | /// Defines which is used by
20 | /// to run animations that require
21 | /// asyncronous initialization
22 | ///
23 | internal class AnimationTask
24 | {
25 | ///
26 | /// Gets or sets that will run before any animation
27 | /// and it will add the animation to the AnimationSet once complete
28 | ///
29 | public Task Task { get; set; }
30 |
31 | ///
32 | /// Gets or sets that will run the animation
33 | ///
34 | public AnimationSet AnimationSet { get; set; }
35 |
36 | ///
37 | /// Gets or sets Duration to be applied to the animation once the task is completed
38 | /// Used when Duration is changed before Task completes
39 | ///
40 | public TimeSpan? Duration { get; set; }
41 |
42 | ///
43 | /// Gets or sets Delay to be applied to the animation once the task is completed
44 | /// Used when Duration is changed before Task completes
45 | ///
46 | public TimeSpan? Delay { get; set; }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Extensions/AnimationTools.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Windows.UI.Xaml;
14 |
15 | namespace Microsoft.Toolkit.Uwp.UI.Animations
16 | {
17 | ///
18 | /// Internal tool to link composite transforms to elements
19 | ///
20 | internal class AnimationTools : DependencyObject
21 | {
22 | ///
23 | /// Attached property used to link composite transform with UIElement
24 | ///
25 | public static readonly DependencyProperty AnimationCompositeTransformIndexProperty = DependencyProperty.RegisterAttached(
26 | "AnimationCompositeTransformIndex",
27 | typeof(int),
28 | typeof(AnimationTools),
29 | new PropertyMetadata(-2));
30 |
31 | ///
32 | /// Attach a composite transform index to an UIElement.
33 | ///
34 | /// UIElement to use
35 | /// Composite transform index
36 | public static void SetAnimationCompositeTransformIndex(UIElement element, int value)
37 | {
38 | element.SetValue(AnimationCompositeTransformIndexProperty, value);
39 | }
40 |
41 | ///
42 | /// Get the composite transform index attached to an UIElement.
43 | ///
44 | /// UIElement to use
45 | /// Composite transform index.
46 | public static int GetAnimationCompositeTransformIndex(UIElement element)
47 | {
48 | return (int)element.GetValue(AnimationCompositeTransformIndexProperty);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Behaviors/Blur.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Windows.UI.Xaml;
14 |
15 | namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
16 | {
17 | ///
18 | /// Performs an blur behind the window animation using composition.
19 | ///
20 | ///
21 | ///
22 | /// Blurs are only supported on Build 1703 and up. Assigning the blur behavior on an older
23 | /// version of Windows will not add any effect. You can use the
24 | /// property to check for whether blurs are supported on the device at runtime.
25 | ///
26 | ///
27 | ///
28 | /// Microsoft.Xaml.Interactivity.Behavior{Windows.UI.Xaml.UIElement}
29 | ///
30 | ///
31 | public class Blur : CompositionBehaviorBase
32 | {
33 | ///
34 | /// The Blur value of the associated object
35 | ///
36 | public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(Blur), new PropertyMetadata(0d, PropertyChangedCallback));
37 |
38 | ///
39 | /// Gets or sets the Blur.
40 | ///
41 | ///
42 | /// The Blur.
43 | ///
44 | public double Value
45 | {
46 | get { return (double)GetValue(ValueProperty); }
47 | set { SetValue(ValueProperty, value); }
48 | }
49 |
50 | ///
51 | /// Starts the animation.
52 | ///
53 | public override void StartAnimation()
54 | {
55 | if (AnimationExtensions.BlurEffect.IsSupported)
56 | {
57 | AssociatedObject?.Blur(duration: Duration, delay: Delay, value: (float)Value)?.Start();
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Effects/Blur.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Microsoft.Graphics.Canvas.Effects;
14 | using Windows.Foundation.Metadata;
15 | using Windows.UI.Composition;
16 |
17 | namespace Microsoft.Toolkit.Uwp.UI.Animations.Effects
18 | {
19 | ///
20 | /// An animation effect that applies blur.
21 | ///
22 | ///
23 | public class Blur : AnimationEffect
24 | {
25 | ///
26 | /// Gets a value indicating whether blur is supported.
27 | ///
28 | ///
29 | /// true if this instance is supported; otherwise, false.
30 | ///
31 | public override bool IsSupported
32 | => ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3);
33 |
34 | ///
35 | /// Gets the name of the effect.
36 | ///
37 | ///
38 | /// The name of the effect.
39 | ///
40 | public override string EffectName { get; } = "Blur";
41 |
42 | ///
43 | /// Applies the effect.
44 | ///
45 | ///
46 | /// An array of strings of the effect properties to change.
47 | ///
48 | public override string[] ApplyEffect()
49 | {
50 | var gaussianBlur = new GaussianBlurEffect
51 | {
52 | Name = EffectName,
53 | BlurAmount = 0f,
54 | Optimization = EffectOptimization.Balanced,
55 | BorderMode = EffectBorderMode.Hard,
56 | Source = new CompositionEffectSourceParameter("source")
57 | };
58 |
59 | var propertyToChange = $"{EffectName}.BlurAmount";
60 | var propertiesToAnimate = new[] { propertyToChange };
61 |
62 | EffectBrush = Compositor.CreateEffectFactory(gaussianBlur, propertiesToAnimate).CreateBrush();
63 | EffectBrush.SetSourceParameter("source", Compositor.CreateHostBackdropBrush());
64 |
65 | return propertiesToAnimate;
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/EasingType.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | namespace Microsoft.Toolkit.Uwp.UI.Animations
14 | {
15 | ///
16 | /// EasingType is used to describe how the animation interpolates between keyframes.
17 | ///
18 | public enum EasingType
19 | {
20 | ///
21 | /// Creates an animation that accelerates with the default EasingType which is specified in AnimationExtensions.DefaultEasingType which is by default Cubic.
22 | ///
23 | Default,
24 |
25 | ///
26 | /// Creates an animation that accelerates or decelerates linear.
27 | ///
28 | Linear,
29 |
30 | ///
31 | /// Creates an animation that accelerates or decelerates using the formula f(t) = t3.
32 | ///
33 | Cubic,
34 |
35 | ///
36 | /// Retracts the motion of an animation slightly before it begins to animate in the path indicated.
37 | ///
38 | Back,
39 |
40 | ///
41 | /// Creates a bouncing effect.
42 | ///
43 | Bounce,
44 |
45 | ///
46 | /// Creates an animation that resembles a spring oscillating back and forth until it comes to rest.
47 | ///
48 | Elastic,
49 |
50 | ///
51 | /// Creates an animation that accelerates or decelerates using a circular function.
52 | ///
53 | Circle,
54 |
55 | ///
56 | /// Creates an animation that accelerates or decelerates using the formula f(t) = t2.
57 | ///
58 | Quadratic,
59 |
60 | ///
61 | /// Creates an animation that accelerates or decelerates using the formula f(t) = t4.
62 | ///
63 | Quartic,
64 |
65 | ///
66 | /// Create an animation that accelerates or decelerates using the formula f(t) = t5.
67 | ///
68 | Quintic,
69 |
70 | ///
71 | /// Creates an animation that accelerates or decelerates using a sine formula.
72 | ///
73 | Sine
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Acrylic Toolkit Blur for UWP
2 | Add HostBackdrop with this library to your UWP app. HostBackdrop adds blur and transparency through the window (by the specified element on XAML). If you want give a Neon look for you app, so this is the lib! This is based on the open-source UWP Community Toolkit.
3 |
4 | # How to use?
5 | The very first thing you need to do, is to add as a [nuget package to your project](https://www.nuget.org/packages/Mika.Toolkit.Uwp.UI.Animations/), or clone this project and add to your solution and reference it.
6 |
7 | After that, you need to add to your XAML these 3 lines first:
8 | ```
9 | xmlns:acrylic="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
10 | xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
11 | ```
12 |
13 | And the app body, you will call Acrylic Blur like this:
14 | ```
15 |
16 |
17 |
19 |
20 |
21 | ```
22 |
23 | You don't need to put it just on Grid's. You can put on almost every XAML element, like SlackPanel, pictures and more.
24 | If you are familiar with XAML and Behaviors, this will be extremally easy for you.
25 | Here is the full "code" on a sample app:
26 |
27 | ``` XAML
28 |
38 |
39 |
40 |
41 |
42 |
44 |
45 |
46 |
47 |
48 | ```
49 |
50 | # Requirements
51 | You can install on Mobile and other devices, but for now, the API used on the library (CreateHostBackdrop) just works on Desktop and it needs Windows 10 version 1703 (build 15063) at least. On devices that is not Desktop, it will show a black background, as the Windows compositor doesn't support yet.
52 |
53 | # Issues and Pull Request
54 | If you have any problems, you can open issues and if you want improvements, you can open Pull Requests any time.
55 |
56 | # Contact
57 | If you want to talk with me and other stuff, https://t.me/vitorgrs on Telegram or https://twitter.com/vitorgrs
58 |
--------------------------------------------------------------------------------
/Extensions/AnimationExtensions.Blur.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Microsoft.Toolkit.Uwp.UI.Animations.Effects;
14 | using Windows.Foundation.Metadata;
15 | using Windows.UI.Xaml;
16 |
17 | namespace Microsoft.Toolkit.Uwp.UI.Animations
18 | {
19 | ///
20 | /// These extension methods perform animation on UIElements
21 | ///
22 | public static partial class AnimationExtensions
23 | {
24 | ///
25 | /// Gets the blur effect.
26 | ///
27 | ///
28 | /// The blur effect.
29 | ///
30 | public static Blur BlurEffect { get; } = new Blur();
31 |
32 | ///
33 | /// Gets a value indicating whether the platform supports blur.
34 | ///
35 | ///
36 | /// A check should always be made to IsBlurSupported prior to calling Blur,
37 | /// since older operating systems will not support blurs.
38 | ///
39 | ///
40 | public static bool IsBlurSupported =>
41 | ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3); // SDK >= 15063
42 |
43 | ///
44 | /// Animates the gaussian blur of the the UIElement.
45 | ///
46 | /// The associated object.
47 | /// The blur amount.
48 | /// The duration in milliseconds.
49 | /// The delay. (ignored if duration == 0)
50 | ///
51 | /// An Animation Set.
52 | ///
53 | ///
54 | public static AnimationSet Blur(
55 | this FrameworkElement associatedObject,
56 | double value = 0d,
57 | double duration = 500d,
58 | double delay = 0d)
59 | {
60 | if (associatedObject == null)
61 | {
62 | return null;
63 | }
64 |
65 | var animationSet = new AnimationSet(associatedObject);
66 | return animationSet.Blur(value, duration, delay);
67 | }
68 |
69 | ///
70 | /// Animates the gaussian blur of the the UIElement.
71 | ///
72 | /// The animation set.
73 | /// The blur amount.
74 | /// The duration in milliseconds.
75 | /// The delay. (ignored if duration == 0)
76 | ///
77 | /// An Animation Set.
78 | ///
79 | ///
80 | public static AnimationSet Blur(
81 | this AnimationSet animationSet,
82 | double value = 0d,
83 | double duration = 500d,
84 | double delay = 0d)
85 | {
86 | return BlurEffect.EffectAnimation(animationSet, value, duration, delay);
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/Microsoft.Toolkit.Uwp.UI.Animations.ruleset:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/Behaviors/CompositionBehaviorBase.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Windows.UI.Xaml;
14 |
15 | namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
16 | {
17 | ///
18 | /// A base class for all behaviors using composition.It contains some of the common propeties to set on a visual.
19 | ///
20 | /// The type of the associated object.
21 | ///
22 | public abstract class CompositionBehaviorBase : BehaviorBase
23 | where T : UIElement
24 | {
25 | ///
26 | /// Called when the associated object has been loaded.
27 | ///
28 | protected override void OnAssociatedObjectLoaded()
29 | {
30 | base.OnAssociatedObjectLoaded();
31 |
32 | if (AutomaticallyStart)
33 | {
34 | StartAnimation();
35 | }
36 | }
37 |
38 | ///
39 | /// The duration of the animation.
40 | ///
41 | public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(nameof(Duration), typeof(double), typeof(CompositionBehaviorBase), new PropertyMetadata(1d, PropertyChangedCallback));
42 |
43 | ///
44 | /// The delay of the animation.
45 | ///
46 | public static readonly DependencyProperty DelayProperty = DependencyProperty.Register(nameof(Delay), typeof(double), typeof(CompositionBehaviorBase), new PropertyMetadata(0d, PropertyChangedCallback));
47 |
48 | ///
49 | /// The property sets if the animation should automatically start.
50 | ///
51 | public static readonly DependencyProperty AutomaticallyStartProperty = DependencyProperty.Register(nameof(AutomaticallyStart), typeof(bool), typeof(CompositionBehaviorBase), new PropertyMetadata(true, PropertyChangedCallback));
52 |
53 | ///
54 | /// Gets or sets a value indicating whether [automatically start] on the animation is set.
55 | ///
56 | ///
57 | /// true if [automatically start]; otherwise, false.
58 | ///
59 | public bool AutomaticallyStart
60 | {
61 | get { return (bool)GetValue(AutomaticallyStartProperty); }
62 | set { SetValue(AutomaticallyStartProperty, value); }
63 | }
64 |
65 | ///
66 | /// Gets or sets the delay.
67 | ///
68 | ///
69 | /// The delay.
70 | ///
71 | public double Delay
72 | {
73 | get { return (double)GetValue(DelayProperty); }
74 | set { SetValue(DelayProperty, value); }
75 | }
76 |
77 | ///
78 | /// Gets or sets the duration.
79 | ///
80 | ///
81 | /// The duration.
82 | ///
83 | public double Duration
84 | {
85 | get { return (double)GetValue(DurationProperty); }
86 | set { SetValue(DurationProperty, value); }
87 | }
88 |
89 | ///
90 | /// Starts the animation.
91 | ///
92 | public abstract void StartAnimation();
93 |
94 | ///
95 | /// If any of the properties are changed then the animation is automatically started depending on the AutomaticallyStart property.
96 | ///
97 | /// The dependency object.
98 | /// The instance containing the event data.
99 | protected static void PropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
100 | {
101 | var behavior = dependencyObject as CompositionBehaviorBase;
102 | if (behavior == null)
103 | {
104 | return;
105 | }
106 |
107 | if (behavior.AutomaticallyStart)
108 | {
109 | behavior.StartAnimation();
110 | }
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/Behaviors/BehaviorBase.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using Microsoft.Xaml.Interactivity;
14 | using Windows.UI.Xaml;
15 |
16 | namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors
17 | {
18 | ///
19 | /// Base class for behaviors that solves 2 problems:
20 | /// 1. Prevent duplicate initialization that can happen (prevent multiple OnAttached calls);
21 | /// 2. Whenever initially fails, this method will subscribe to to allow lazy initialization.
22 | ///
23 | /// The type of the associated object.
24 | ///
25 | ///
26 | /// For more info, see https://github.com/Microsoft/UWPCommunityToolkit/issues/1008.
27 | ///
28 | public abstract class BehaviorBase : Behavior
29 | where T : UIElement
30 | {
31 | private bool _isAttaching;
32 | private bool _isAttached;
33 |
34 | ///
35 | /// Gets a value indicating whether this behavior is attached.
36 | ///
37 | ///
38 | /// true if this behavior is attached; otherwise, false.
39 | ///
40 | protected bool IsAttached
41 | {
42 | get { return _isAttached; }
43 | }
44 |
45 | ///
46 | /// Called after the behavior is attached to the .
47 | ///
48 | ///
49 | /// Override this to hook up functionality to the
50 | ///
51 | protected override void OnAttached()
52 | {
53 | base.OnAttached();
54 |
55 | HandleAttach();
56 |
57 | var frameworkElement = AssociatedObject as FrameworkElement;
58 | if (frameworkElement != null)
59 | {
60 | frameworkElement.Loaded += OnAssociatedObjectLoaded;
61 | frameworkElement.Unloaded += OnAssociatedObjectUnloaded;
62 | frameworkElement.SizeChanged += OnAssociatedObjectSizeChanged;
63 | }
64 | }
65 |
66 | ///
67 | /// Called when the behavior is being detached from its .
68 | ///
69 | ///
70 | /// Override this to unhook functionality from the
71 | ///
72 | protected override void OnDetaching()
73 | {
74 | base.OnDetaching();
75 |
76 | var frameworkElement = AssociatedObject as FrameworkElement;
77 | if (frameworkElement != null)
78 | {
79 | frameworkElement.Loaded -= OnAssociatedObjectLoaded;
80 | frameworkElement.Unloaded -= OnAssociatedObjectUnloaded;
81 | frameworkElement.SizeChanged -= OnAssociatedObjectSizeChanged;
82 | }
83 |
84 | HandleDetach();
85 | }
86 |
87 | ///
88 | /// Called when the associated object has been loaded.
89 | ///
90 | protected virtual void OnAssociatedObjectLoaded()
91 | {
92 | }
93 |
94 | ///
95 | /// Called when the associated object has been unloaded.
96 | ///
97 | protected virtual void OnAssociatedObjectUnloaded()
98 | {
99 | }
100 |
101 | ///
102 | /// Initializes the behavior to the associated object.
103 | ///
104 | /// true if the initialization succeeded; otherwise false.
105 | protected virtual bool Initialize()
106 | {
107 | return true;
108 | }
109 |
110 | ///
111 | /// Uninitializes the behavior from the associated object.
112 | ///
113 | /// true if uninitialization succeeded; otherwise false.
114 | protected virtual bool Uninitialize()
115 | {
116 | return true;
117 | }
118 |
119 | private void OnAssociatedObjectLoaded(object sender, RoutedEventArgs e)
120 | {
121 | if (!_isAttached)
122 | {
123 | HandleAttach();
124 | }
125 |
126 | OnAssociatedObjectLoaded();
127 | }
128 |
129 | private void OnAssociatedObjectUnloaded(object sender, RoutedEventArgs e)
130 | {
131 | OnAssociatedObjectUnloaded();
132 |
133 | // Note: don't detach here, we'll let the behavior implementation take care of that
134 | }
135 |
136 | private void OnAssociatedObjectSizeChanged(object sender, SizeChangedEventArgs e)
137 | {
138 | if (!_isAttached)
139 | {
140 | HandleAttach();
141 | }
142 | }
143 |
144 | private void HandleAttach()
145 | {
146 | if (_isAttaching || _isAttached)
147 | {
148 | return;
149 | }
150 |
151 | _isAttaching = true;
152 |
153 | var attached = Initialize();
154 | if (attached)
155 | {
156 | _isAttached = true;
157 | }
158 |
159 | _isAttaching = false;
160 | }
161 |
162 | private void HandleDetach()
163 | {
164 | if (!_isAttached)
165 | {
166 | return;
167 | }
168 |
169 | var detached = Uninitialize();
170 | if (detached)
171 | {
172 | _isAttached = false;
173 | }
174 | }
175 | }
176 | }
--------------------------------------------------------------------------------
/Extensions/AnimationExtensions.cs:
--------------------------------------------------------------------------------
1 | // ******************************************************************
2 | // Copyright (c) Microsoft. All rights reserved.
3 | // This code is licensed under the MIT License (MIT).
4 | // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10 | // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11 | // ******************************************************************
12 |
13 | using System;
14 | using System.Threading.Tasks;
15 | using Windows.UI.Xaml;
16 | using Windows.UI.Xaml.Media;
17 | using Windows.UI.Xaml.Media.Animation;
18 |
19 | namespace Microsoft.Toolkit.Uwp.UI.Animations
20 | {
21 | ///
22 | /// These extension methods perform animation on UIElements
23 | ///
24 | public static partial class AnimationExtensions
25 | {
26 | ///
27 | /// Gets or sets the default EasingType used for storyboard animations
28 | ///
29 | public static EasingType DefaultEasingType { get; set; } = EasingType.Cubic;
30 |
31 | ///
32 | /// Begins a Storyboard animation and returns a task that completes when the
33 | /// animaton is complete
34 | ///
35 | /// The storyoard to be started
36 | /// Task that completes when the animation is complete
37 | public static Task BeginAsync(this Storyboard storyboard)
38 | {
39 | var taskSource = new TaskCompletionSource