How to invert clipping geometry in Silverlight/WPF?

和自甴很熟 提交于 2019-12-21 07:22:29

问题


The UIElement.Clip property takes a Geometry object and uses it to clip away the outside of the UIElement. I would like to do the geometric inverse and punch a hole into the element instead.

Anyone know how to do this?

I imagine creating an inverted version of the clip geometry would work, but I can't find a way to do this.


EDIT It seems that WPF has Geometry.Combine which can be used to subtract one geometry from another, though this isn't available in Silverlight. If it were, I could subtract the clip geometry from the rectangle of the element's bounding rectangle, and use that to clip instead.


回答1:


One approach in Silverlight is to use a GeometryGroup and include in the group a very large rectangle starting at a distant negative position.

For example the following blue square has smaller square hole:-

    <Rectangle Fill="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="200" Width="200">
        <Rectangle.Clip>
            <GeometryGroup>
                <RectangleGeometry Rect="-2048 -2048 4096 4096" />
                <RectangleGeometry Rect="100 100 50 50" />
            </GeometryGroup>
        </Rectangle.Clip>
    </Rectangle>


来源:https://stackoverflow.com/questions/7705612/how-to-invert-clipping-geometry-in-silverlight-wpf

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