UIElement.ClipToBounds is in WPF, but not in Silverlight. How to simulate in Silverlight?

I have Canvas in WPF and I want its children not to be drawn outside the borders of Canvas ara. In WPF, it's simple, because you just set the ClipToBounds property on the Canvas to True, and it works as expected.

Porting a XAML sample to Silverlight occurs because ClipToBounds does not exist! Is there any way to simulate this functionality? I am happy to get from Canvas and override the Measure / Arrange methods, if necessary.

+4
source share
1 answer

I found a solution myself. Override ArrangeOverride method like this ...

protected override Size ArrangeOverride(Size finalSize) { RectangleGeometry clipRectGeometry = new RectangleGeometry(); clipRectGeometry.Rect = new Rect(new Point(0,0), finalSize); Clip = clipRectGeometry; return base.ArrangeOverride(); } 
+7
source

All Articles