tags:

views:

206

answers:

1

Hello,

when using OnRender to draw something on the screen, is there any way to perform Hit Testing on the drawn graphics?

Sample Code

    protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
    {
        base.OnRender(drawingContext);

        drawingContext.DrawRectangle(Brushes.Black, null, new Rect(50, 50, 100, 100));
    }

Obviously one has no reference to the drawn Rectangle which would be necessary to perform hit testing or am I wrong about this? I know I can use DrawingVisual, I'm just curious if my understanding is correct, that using OnRender to draw something you can't perform any hit testing on the drawn things?

+1  A: 

You understood right, there is no way do hittesting on the graphics you have drawn using the DrawingContext methods because they are not represented as objects in the visual tree.

bitbonk
thanks for your confirmation and explanation :-)
stefan.at.wpf