diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs index 1a1b158f334..b79d0633a7a 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/UIElementExtensions.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Numerics; +using Windows.UI.Composition; using Windows.UI.Xaml; using Windows.UI.Xaml.Hosting; @@ -48,10 +50,10 @@ public static void SetVisualFactory(UIElement element, AttachedVisualFactoryBase /// The instance for the current event. private static async void OnVisualFactoryPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - var element = (UIElement)d; - var attachedVisual = await ((AttachedVisualFactoryBase)e.NewValue).GetAttachedVisualAsync(element); + UIElement element = (UIElement)d; + Visual attachedVisual = await ((AttachedVisualFactoryBase)e.NewValue).GetAttachedVisualAsync(element); - attachedVisual.BindSize(element); + attachedVisual.RelativeSizeAdjustment = Vector2.One; ElementCompositionPreview.SetElementChildVisual(element, attachedVisual); } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/Windows.UI.Composition/CompositionObjectExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/Windows.UI.Composition/CompositionObjectExtensions.cs index 44309317b27..0cb56abdb7f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Extensions/Windows.UI.Composition/CompositionObjectExtensions.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Extensions/Windows.UI.Composition/CompositionObjectExtensions.cs @@ -18,11 +18,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Media internal static class CompositionObjectExtensions { /// - /// Starts an to keep the size of the source in sync with the target + /// Starts an to keep the size of the source in sync with the target /// - /// The to start the animation on + /// The to start the animation on /// The target to read the size updates from - public static void BindSize(this CompositionObject source, UIElement target) + public static void BindSize(this Visual source, UIElement target) { var visual = ElementCompositionPreview.GetElementVisual(target); var bindSizeAnimation = source.Compositor.CreateExpressionAnimation($"{nameof(visual)}.Size"); diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs index 3180aeb4c05..d6433b2d6c2 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.Contracts; +using System.Numerics; using System.Threading.Tasks; using Microsoft.Toolkit.Uwp.UI.Animations; using Windows.Graphics.Effects; @@ -188,7 +189,7 @@ public async Task BuildAsync() /// A that returns the final instance to use public async Task AttachAsync(UIElement target, UIElement reference = null) { - var visual = Window.Current.Compositor.CreateSpriteVisual(); + SpriteVisual visual = Window.Current.Compositor.CreateSpriteVisual(); visual.Brush = await BuildAsync(); @@ -196,7 +197,14 @@ public async Task AttachAsync(UIElement target, UIElement referenc if (reference != null) { - visual.BindSize(reference); + if (reference == target) + { + visual.RelativeSizeAdjustment = Vector2.One; + } + else + { + visual.BindSize(reference); + } } return visual;