简体   繁体   English

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

[英]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.

相关问题 如何从用户控件中检索其他用户控件信息? - How to retrieve other user controls information from user control? 如何基于绑定列表构建包含其他控件的 WPF 控件 - How to build a WPF control containing other controls based on a bound list 如何将ListView控件置于WPF中的其他控件之上 - How I can bring ListView control in top of other controls in WPF 将控件保持在可见区域 - Keeping controls in the visible area 当下拉控件与页面上的任何其他控件重叠时,其可见性优先级更高 - Dropdown controls get higher precedence in visibility when overlapped by any other control on page 在WinForms中集成WPF控件而不允许访问其他WPF控件? - Integrating a WPF control in WinForms without allowing access to other WPF controls? 使用WPF,如何检索DataTemplate包含的控件? - With WPF, how to retrieve the controls contained by a DataTemplate? 确定控件的可见区域 - Determine visible area of a control 如何在WPF控件/控件集中获得与具有链接到其他页面内容的HTML相同的行为? - How can I get the same behavior in a WPF control/set of controls as that of HTML with links to other page content? c# WPF - 如何在不阻止其他控件可点击的情况下识别控件外的鼠标单击 - c# WPF - How to recognize mouse click outside control without blocking other controls from being clickable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM