Uielement.cliptobounds is in WPF, but not in Silverlight. How to simulate in Silverlight?

I have a Canvas in WPF, and I want to prevent its children from being drawn outside the edge of Canvas ara. In WPF, this is very simple, because you only need to put the Canvas on Set the ClipToBounds property to True and it will execute as expected.

There is a problem with porting the sample XAML to Silverlight, because ClipToBounds does not exist! Is there a way to simulate this function? I am happy to derive from Canvas and override the Measure / Arrange method when needed.

I found it myself Solution. Override the 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();
)

I have a Canvas in WPF, and I want to prevent its children from being drawn outside the edge of Canvas ara. In WPF, this is simple because You only need to set the ClipToBounds property on the Canvas to True, and it will execute as expected.

There is a problem with porting the sample XAML to Silverlight, because ClipToBounds does not exist! Is there a way to simulate this function? I am happy to derive from Canvas and override the Measure / Arrange method when needed.

I found the solution myself. Override the 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();
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4059 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.