Skip to content

Commit b88e4a2

Browse files
Clean-up ShadowAnimation type and add rest of animatable properties
1 parent 71322fc commit b88e4a2

File tree

6 files changed

+84
-12
lines changed

6 files changed

+84
-12
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/XamlOnlyPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
<ani:SaturationEffectAnimation />
6767
<ani:AnimationScope />
6868
<ani:ExposureEffectAnimation />
69+
<ani:BlurRadiusDropShadowAnimation />
70+
<ani:ColorDropShadowAnimation />
6971
<ani:OffsetDropShadowAnimation />
72+
<ani:OpacityDropShadowAnimation />
7073
</ani:AnimationSet>
7174
</ani:Explicit.Animations>
7275
<media:UIElementExtensions.VisualFactory>
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@
1313
namespace Microsoft.Toolkit.Uwp.UI.Animations
1414
{
1515
/// <summary>
16-
/// A custom animation targeting a property on an <see cref="AttachedShadowBase"/> instance.
16+
/// A custom animation targeting a property on an <see cref="IAttachedShadow"/> instance.
1717
/// </summary>
18-
/// <typeparam name="TShadow">The <see cref="FrameworkElement"/> containing the shadow to animate.</typeparam>
1918
/// <typeparam name="TValue">
2019
/// The type to use for the public <see cref="Animation{TValue,TKeyFrame}.To"/> and <see cref="Animation{TValue,TKeyFrame}.From"/>
2120
/// properties. This can differ from <typeparamref name="TKeyFrame"/> to facilitate XAML parsing.
2221
/// </typeparam>
2322
/// <typeparam name="TKeyFrame">The actual type of keyframe values in use.</typeparam>
24-
public abstract class ShadowAnimation<TShadow, TValue, TKeyFrame> : Animation<TValue, TKeyFrame>, IAttachedTimeline
25-
where TShadow : AttachedShadowBase
23+
public abstract class ShadowAnimation<TValue, TKeyFrame> : Animation<TValue, TKeyFrame>, IAttachedTimeline
2624
where TKeyFrame : unmanaged
2725
{
2826
/// <summary>
29-
/// Gets or sets the linked <typeparamref name="TShadow"/> instance to animate.
27+
/// Gets or sets the linked <see cref="IAttachedShadow"/> instance to animate.
3028
/// </summary>
31-
public TShadow? Target
29+
public IAttachedShadow? Target
3230
{
33-
get => (TShadow?)GetValue(TargetProperty);
31+
get => (IAttachedShadow?)GetValue(TargetProperty);
3432
set => SetValue(TargetProperty, value);
3533
}
3634

@@ -39,8 +37,8 @@ public TShadow? Target
3937
/// </summary>
4038
public static readonly DependencyProperty TargetProperty = DependencyProperty.Register(
4139
nameof(Target),
42-
typeof(TShadow),
43-
typeof(ShadowAnimation<TShadow, TValue, TKeyFrame>),
40+
typeof(IAttachedShadow),
41+
typeof(ShadowAnimation<TValue, TKeyFrame>),
4442
new PropertyMetadata(null));
4543

4644
/// <inheritdoc/>
@@ -63,7 +61,7 @@ static AnimationBuilder ThrowArgumentNullException()
6361
return ThrowArgumentNullException();
6462
}
6563

66-
if (Target is TShadow allShadows)
64+
if (Target is IAttachedShadow allShadows)
6765
{
6866
// in this case we'll animate all the shadows being used.
6967
foreach (var context in allShadows.GetElementContextEnumerable()) //// TODO: Find better way!!!
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Windows.UI.Composition;
6+
7+
namespace Microsoft.Toolkit.Uwp.UI.Animations
8+
{
9+
/// <summary>
10+
/// A blur radius animation working on the composition layer.
11+
/// </summary>
12+
public sealed class BlurRadiusDropShadowAnimation : ShadowAnimation<double?, double>
13+
{
14+
/// <inheritdoc/>
15+
protected override string ExplicitTarget => nameof(DropShadow.BlurRadius);
16+
17+
/// <inheritdoc/>
18+
protected override (double?, double?) GetParsedValues()
19+
{
20+
return (To, From);
21+
}
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Windows.UI;
6+
using Windows.UI.Composition;
7+
8+
#pragma warning disable CS0419
9+
10+
namespace Microsoft.Toolkit.Uwp.UI.Animations
11+
{
12+
/// <summary>
13+
/// A custom <see cref="Color"/> animation on a <see cref="DropShadow"/>.
14+
/// </summary>
15+
public sealed class ColorDropShadowAnimation : ShadowAnimation<Color?, Color>
16+
{
17+
/// <inheritdoc/>
18+
protected override string ExplicitTarget => nameof(DropShadow.Color);
19+
20+
/// <inheritdoc/>
21+
protected override (Color?, Color?) GetParsedValues()
22+
{
23+
return (To, From);
24+
}
25+
}
26+
}

Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Shadows/OffsetDropShadowAnimation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
using System.Numerics;
66
using Windows.UI.Composition;
7-
using Windows.UI.Xaml;
87

98
namespace Microsoft.Toolkit.Uwp.UI.Animations
109
{
1110
/// <summary>
1211
/// An offset animation working on the composition layer.
1312
/// </summary>
14-
public sealed class OffsetDropShadowAnimation : ShadowAnimation<AttachedShadowBase, string, Vector3>
13+
public sealed class OffsetDropShadowAnimation : ShadowAnimation<string, Vector3>
1514
{
1615
/// <inheritdoc/>
1716
protected override string ExplicitTarget => nameof(DropShadow.Offset);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Windows.UI.Composition;
6+
7+
namespace Microsoft.Toolkit.Uwp.UI.Animations
8+
{
9+
/// <summary>
10+
/// An opacity animation working on the composition layer.
11+
/// </summary>
12+
public sealed class OpacityDropShadowAnimation : ShadowAnimation<double?, double>
13+
{
14+
/// <inheritdoc/>
15+
protected override string ExplicitTarget => nameof(DropShadow.Opacity);
16+
17+
/// <inheritdoc/>
18+
protected override (double?, double?) GetParsedValues()
19+
{
20+
return (To, From);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)