【发布时间】:2014-09-13 14:56:32
【问题描述】:
我正在使用下面的代码来查看鼠标右键单击的时间,它是否击中目标 (Drawing)。
现在,如果鼠标击中目标,将显示一条消息,说明我们击中了目标。
但是我可以在哪里显示目标未命中的消息? VisualTreeHelper.HitTest() 似乎没有返回指示目标是否被击中的值。
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));
// Where should I put the MessageBox.Show("You did not hit the target");
// If I put it here it is displayed anyway
}
private HitTestResultBehavior MyCallback(HitTestResult result)
{
MessageBox.Show("You hit the target");
return HitTestResultBehavior.Stop;
}
【问题讨论】: