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

余生长醉 提交于 2020-01-03 19:33:13

问题


I have a Canvas in WPF and I want to prevent its children from being drawn outside the edges of the Canvas ara. In WPF this is simple as you just set the ClipToBounds property on the Canvas to True and it does as expected.

Porting the sample XAML to Silverlight there is an issue because ClipToBounds does not exist! Is there a way to simulate this functionality? I am happy to derive from Canvas and override the Measure/Arrange methods if needed.


回答1:


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();
}


来源:https://stackoverflow.com/questions/692585/uielement-cliptobounds-is-in-wpf-but-not-silverlight-how-to-simulate-in-silverl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!