forum

Home / DeveloperSection / Forums / Check if a target was not hit in WPF

Check if a target was not hit in WPF

Anonymous User 2314 14-Nov-2014

I'm using the code below to see when the mouse right button is clicked, if it hits a target (Drawing) or not.

Now If the mouse hits the target a message will be shown stating that we hit the target.

But where can I show a message that the target was NOT hit? VisualTreeHelper.HitTest() doesn't seem to return a value indicating that the target was hit or not.

private void OnMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
    var x = MousePos.RightDown.X;
    var y = MousePos.RightDown.Y;
    var hitRect = new Rect(x - 2, y - 2, 4, 4);
    var geom = new RectangleGeometry(hitRect);
    VisualTreeHelper.HitTest(Drawing,                          null,
                             MyCallback,
                             new GeometryHitTestParameters(geom));
}
private HitTestResultBehavior MyCallback(HitTestResult result)
{
    MessageBox.Show("You hit the target");
    return HitTestResultBehavior.Stop;
}


wpf c# 
Updated on 15-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By