Skip to content

Commit cfe7db2

Browse files
committed
Fixed clipping when an unloaded Marquee's size changes
1 parent d2a1ff1 commit cfe7db2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

components/Marquee/src/Marquee.Events.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ private void Marquee_Loaded(object sender, RoutedEventArgs e)
5656
_marqueeStoryboard.Completed += StoryBoard_Completed;
5757
}
5858

59+
// The size may have channged while unloaded.
60+
// Clip the marquee
61+
ClipMarquee();
62+
5963
// Setup the animation
6064
UpdateMarquee(false);
6165

@@ -93,11 +97,8 @@ private void Container_SizeChanged(object sender, SizeChangedEventArgs e)
9397
if (_marqueeContainer is null)
9498
return;
9599

96-
// Clip the marquee within its bounds
97-
_marqueeContainer.Clip = new RectangleGeometry
98-
{
99-
Rect = new Rect(0, 0, e.NewSize.Width, e.NewSize.Height)
100-
};
100+
// Clip the marquee
101+
ClipMarquee(e.NewSize.Width, e.NewSize.Height);
101102

102103
// Update animation on the fly
103104
UpdateMarquee(true);

components/Marquee/src/Marquee.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,19 @@ private Storyboard CreateMarqueeStoryboardAnimation(double start, double end, Ti
456456

457457
return marqueeStoryboard;
458458
}
459+
460+
private void ClipMarquee(double width = default, double height = default)
461+
{
462+
if (_marqueeContainer is null)
463+
return;
464+
465+
width = width is default(double) ? _marqueeContainer.ActualWidth : width;
466+
height = height is default(double) ? _marqueeContainer.ActualHeight : height;
467+
468+
// Clip the marquee within the bounds of the container
469+
_marqueeContainer.Clip = new RectangleGeometry
470+
{
471+
Rect = new Rect(0, 0, width, height)
472+
};
473+
}
459474
}

0 commit comments

Comments
 (0)