From 17c09d493e6610a7f9cbf67b9553546702fe1506 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sun, 1 Jun 2025 21:58:38 -0500 Subject: [PATCH] Fix leak from autohide storyboard The storyboard maintained a reference to AutoHideElement even after the window closed. We don't need a storyboard anyway, so stop using it to avoid the problem. --- src/ManagedShell.AppBar/AppBarWindow.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/ManagedShell.AppBar/AppBarWindow.cs b/src/ManagedShell.AppBar/AppBarWindow.cs index a2a01211..79681177 100644 --- a/src/ManagedShell.AppBar/AppBarWindow.cs +++ b/src/ManagedShell.AppBar/AppBarWindow.cs @@ -92,6 +92,7 @@ public FrameworkElement AutoHideElement set { _autoHideElement = value; + _autoHideElement.RenderTransform = new TranslateTransform(); OnPropertyChanged(); } } @@ -225,12 +226,6 @@ private void AnimateAutoHide(bool isHiding, bool immediate = false) animation.BeginTime = TimeSpan.FromMilliseconds(immediate ? 0 : isHiding ? AutoHideDelayMs : AutoHideShowDelayMs); animation.EasingFunction = new SineEase(); - Storyboard.SetTarget(animation, AutoHideElement); - Storyboard.SetTargetProperty(animation, new PropertyPath($"RenderTransform.(TranslateTransform.{(Orientation == Orientation.Horizontal ? 'Y' : 'X')})")); - - var storyboard = new Storyboard(); - storyboard.Children.Add(animation); - animation.CurrentStateInvalidated += (object sender, EventArgs e) => { if (((AnimationClock)sender).CurrentState == ClockState.Active) { @@ -238,11 +233,11 @@ private void AnimateAutoHide(bool isHiding, bool immediate = false) } }; - storyboard.Completed += (object sender, EventArgs e) => { + animation.Completed += (object sender, EventArgs e) => { OnAutoHideAnimationComplete(isHiding); }; - storyboard.Begin(AutoHideElement); + AutoHideElement.RenderTransform.BeginAnimation(Orientation == Orientation.Horizontal ? TranslateTransform.YProperty : TranslateTransform.XProperty, animation); } protected void PeekDuringAutoHide(int msToPeek = 1000) @@ -368,6 +363,8 @@ private void OnClosing(object sender, CancelEventArgs e) { UnregisterAppBar(); _appBarManager.UnregisterAutoHideBar(this); + AutoHideElement?.RenderTransform?.BeginAnimation(TranslateTransform.YProperty, null); + AutoHideElement?.RenderTransform?.BeginAnimation(TranslateTransform.XProperty, null); // unregister full-screen notifications _fullScreenHelper.FullScreenApps.CollectionChanged -= FullScreenApps_CollectionChanged;