File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,15 @@ private void Marquee_Loaded(object sender, RoutedEventArgs e)
5555 {
5656 _marqueeStoryboard . Completed += StoryBoard_Completed ;
5757 }
58+
59+ // Setup the animation
60+ UpdateMarquee ( false ) ;
61+
62+ // The marquee should run when loaded if auto play is enabled
63+ if ( AutoPlay )
64+ {
65+ StartMarquee ( ) ;
66+ }
5867 }
5968
6069 private void Marquee_Unloaded ( object sender , RoutedEventArgs e )
Original file line number Diff line number Diff line change @@ -53,6 +53,12 @@ public partial class Marquee : ContentControl
5353 private bool _isActive = false ;
5454 private bool _isPaused = false ;
5555
56+ // This is used to track the position when stopped.
57+ // If the animation update happens while running, this position
58+ // is lost and must be set when the animation stops.
59+ private double _stoppedPosition ;
60+ private DependencyProperty ? _animationProperty ;
61+
5662 /// <summary>
5763 /// Initializes a new instance of the <see cref="Marquee"/> class.
5864 /// </summary>
@@ -180,6 +186,12 @@ public void StopMarquee()
180186 _isActive = false ;
181187 _isPaused = false ;
182188
189+ // Set the transform to the stopped position if provided.
190+ if ( _animationProperty is not null )
191+ {
192+ _marqueeTransform ? . SetValue ( _animationProperty , _stoppedPosition ) ;
193+ }
194+
183195 if ( ! wasStopped )
184196 {
185197 // Apply state transitions
@@ -380,6 +392,11 @@ private bool UpdateAnimation(out TimeSpan seekPoint)
380392 _marqueeTransform . SetValue ( dp , start ) ;
381393 }
382394
395+ // Set stopped position and animation property regardless of the active state.
396+ // This will be used when the animation stops.
397+ _stoppedPosition = start ;
398+ _animationProperty = dp ;
399+
383400 return true ;
384401 }
385402
You can’t perform that action at this time.
0 commit comments