WPF - 路径/几何帮助 - 奇怪的形状 [英] WPF - Path/Geometry help - Strange shape

查看:31
本文介绍了WPF - 路径/几何帮助 - 奇怪的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道从 Xaml 创建这个对象的好方法吗?当它叠加在其他控件之上时,它也必须在 0.5 Opacity 下工作.

Anyone know a good way to create this object from Xaml? It also has to work at .5 Opacity when layered on top of other controls.

它还必须通过水平或垂直对齐来调整大小.

It also has to be resizable via Horizontal or Vertical Alignment.

我遇到了一些困难.我得到的最接近的是 2 个边框,一个有负边距 - 但在应用不透明度时它不起作用.

I'm having some difficulty. The closest I get is with 2 borders, one having a negative margin--but it doesn't work when Opacity is applied.

有效的代码:

<Path Fill="Black">
    <Path.Data>
        <CombinedGeometry GeometryCombineMode="Exclude">
            <CombinedGeometry.Geometry1>
                <RectangleGeometry RadiusX="5" RadiusY="5" Rect="0,0,200,100" />
            </CombinedGeometry.Geometry1>
            <CombinedGeometry.Geometry2>
                <RectangleGeometry RadiusX="5" RadiusY="5" Rect="105,5,90,90" />
            </CombinedGeometry.Geometry2>
        </CombinedGeometry>
    </Path.Data>
</Path>

推荐答案

使用 GeometryGroup 带有 EvenOdd FillRule 或 CombinedGeometry 与 GeometryCombineMode 的异或或排除.要组合的几何图形都是 RectangleGeometry 对象,具有适当的 RadiusX 和 RadiusY.结果将是内部矩形所在的外部矩形,其中有一个洞".(我假设这是您想要的,而不是黑色矩形内的白色矩形.)

Use a GeometryGroup with an EvenOdd FillRule, or a CombinedGeometry with a GeometryCombineMode of Xor or Exclude. The geometries to combine will both be RectangleGeometry objects, with an appropriate RadiusX and RadiusY. The result will be the outer rectangle with a "hole" in it where the inner rectangle was located. (I assume this is what you want rather than a white rectangle within the black one.)

然后,您可以将此复合几何图形作为其数据属性分配给路径,并根据需要设置填充和不透明度.

You can then assign this composite geometry to a Path as its Data property, and set the Fill and Opacity as required.

这篇关于WPF - 路径/几何帮助 - 奇怪的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆