4
votes

I need to determine the visible area/areas of a WPF control overlapped by other controls taking in consideration transparency.

Consider the following scenario: enter image description here

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?

Something similar to (following API doesn't exist):

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.

Then use CombinedGeometry with GeometryCombineMode="Union" on the overlapping controls to get the overlapping area.

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.

The problem is that VisualTreeHelper.GetDrawing(control) returns null.

1

1 Answers

1
votes

Have you already tried to use HitTest? It may be helpful

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