我不清楚为什么当您将手悬停在另一个对象上时会禁用另一个按钮。如果没有看到代码,我会说你正在做一些会导致这种情况的事情——而且没有理由这样做。
此外,您应该使用以手势系统为中心的交互概念,而不是为鼠标/键盘输入而编写的东西。使用常规 UI 对象并以平行传统输入的方式与它们交互只会混淆用户。
看看下面两个例子,它们使用“悬停点击”和“按下点击”交互
在这两种情况下,您都在自定义控件上使用命中测试来处理事件。以下是我在其中一个应用中使用的命中测试功能示例:
private void HitTestHand(HandPosition hand)
{
// quick fix to null pointer exception on exit.
if (Application.Current.MainWindow == null)
return;
Point pt = new Point(hand.X, hand.Y);
IInputElement input = Application.Current.MainWindow.InputHitTest(pt);
if (hand.CurrentElement != input)
{
var inputObject = input as DependencyObject;
var currentObject = hand.CurrentElement as DependencyObject;
// If the new input is a child of the current element then don't fire the leave event.
// It will be fired later when the current input moves to the parent of the current element.
if (hand.CurrentElement != null && Utility.IsElementChild(currentObject, inputObject) == false)
{
// Raise the HandLeaveEvent on the CurrentElement, which at this point is the previous element the hand was over.
hand.CurrentElement.RaiseEvent(new HandInputEventArgs(HoverDwellButton.HandLeaveEvent, hand.CurrentElement, hand));
}
// If the current element is the parent of the new input element then don't
// raise the entered event as it has already been fired.
if (input != null && Utility.IsElementChild(inputObject, currentObject) == false)
{
input.RaiseEvent(new HandInputEventArgs(HoverDwellButton.HandEnterEvent, input, hand));
}
hand.CurrentElement = input;
}
else if (hand.CurrentElement != null)
{
hand.CurrentElement.RaiseEvent(new HandInputEventArgs(HoverDwellButton.HandMoveEvent, hand.CurrentElement, hand));
}
}
请注意,在手形光标下方的元素上触发了一个事件。这些元素的示例可以在上面的两个链接中找到(HoverDwellButton 是我在上面的代码示例中使用的)。
两个不同元素或同一个元素上的两个事件可以随时触发。您可以轻松跟踪哪个用户在哪个按钮上,该按钮是否正在被按下,或者它是否已被按下。
这一切的关键是不使用不是为手势系统设计的 UI 范例!不要试图将键盘/鼠标事件结构硬塞进一个基于手势的系统中——从长远来看,这只会给你带来更多的痛苦,并让你的用户感到困惑。