[英]How to retrieve the visible area/areas of a WPF control overlapped by other controls considering transparency?
I need to determine the visible area/areas of a WPF control overlapped by other controls taking in consideration transparency. 我需要考虑透明度来确定WPF控件的可见区域/区域与其他控件重叠。
Consider the following scenario: 请考虑以下情形:
Three controls on a canvas. 画布上的三个控件。 The blue and the green one are overlapping the third one.
蓝色和绿色与第三个重叠。 The green one has a transparent rectangle area.
绿色的有一个透明的矩形区域。 Is it possible to problematically get the visible regions 1, 2, 3 marked by red rectangles?
是否有可能有问题地得到红色矩形标记的可见区域1,2,3?
Something similar to (following API doesn't exist): 类似的东西(以下API不存在):
Geometry[] visibleAreas = VisualTreeHelper.GetVisibleGeometry(controlInTheBack);
Thanks in advance for any suggestions. 在此先感谢您的任何建议。
Update: 更新:
I've tried to use DrawingGroup drawingGroup = VisualTreeHelper.GetDrawing(visual) to get the geometries of each control. 我试图使用DrawingGroup drawingGroup = VisualTreeHelper.GetDrawing(visual)来获取每个控件的几何。
Then use CombinedGeometry with GeometryCombineMode="Union" on the overlapping controls to get the overlapping area. 然后在重叠控件上使用CombinedGeometry和GeometryCombineMode =“Union”来获取重叠区域。
Then use CombinedGeometry with GeometryCombineMode="Exclude" between the geometry of the control in the back and the result of the union to obtain the visible regions. 然后在后面的控件的几何体和union的结果之间使用CombinedGeometry和GeometryCombineMode =“Exclude”来获得可见区域。
The problem is that VisualTreeHelper.GetDrawing(control) returns null. 问题是VisualTreeHelper.GetDrawing(控件)返回null。
Have you already tried to use HitTest? 你有没有尝试过使用HitTest? It may be helpful
它可能会有所帮助
http://msdn.microsoft.com/en-us/library/ms752097.aspx http://msdn.microsoft.com/en-us/library/ms752097.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.