如何检测WPF控件的可见区域/区域与其他控件重叠考虑透明度?

时间:2011-11-18 06:05:13

标签: c# wpf xaml

我需要考虑透明度,确定其他控件重叠的WPF控件的可见区域/区域。

请考虑以下情形: enter image description here

画布上的三个控件。蓝色和绿色与第三​​个重叠。绿色的有一个透明的矩形区域。是否有可能有问题地得到红色矩形标记的可见区域1,2,3?

类似于(以下API不存在):

Geometry[] visibleAreas = VisualTreeHelper.GetVisibleGeometry(controlInTheBack);

提前感谢任何建议。

更新

我尝试使用DrawingGroup drawingGroup = VisualTreeHelper.GetDrawing(visual)来获取每个控件的几何。

然后在重叠控件上使用CombinedGeometry和GeometryCombineMode =“Union”来获得重叠区域。

然后在后面的控件的几何图形和联合的结果之间使用CombinedGeometry和GeometryCombineMode =“Exclude”来获得可见区域。

问题是VisualTreeHelper.GetDrawing(control)返回null。

1 个答案:

答案 0 :(得分:1)

您是否已尝试使用HitTest?这可能会有所帮助

http://msdn.microsoft.com/en-us/library/ms752097.aspx