1

我正在使用 Kinect SDK 1.7 创建一个 WPF 应用程序,我需要计算用户放置按钮的次数(不是按下,只是放置)。我发现只有一个事件负责在 XAML 中按下按钮

<k:KinectTileButton Label="Click" Click="PushButtonEvent"></k:KinectTileButton>

我找不到哪个事件负责将手放在按钮上(如果此事件存在)。也许你已经知道哪个事件会做到这一点?或者如何以另一种方式解决这个问题?

4

2 回答 2

2

支持手形光标的KinectTileButton跟随事件,可以订阅并根据您的需要采取行动:

public static readonly RoutedEvent HandPointerMoveEvent = EventManager.RegisterRoutedEvent(
    "HandPointerMove", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerEnterEvent = EventManager.RegisterRoutedEvent(
    "HandPointerEnter", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerLeaveEvent = EventManager.RegisterRoutedEvent(
    "HandPointerLeave", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerPressEvent = EventManager.RegisterRoutedEvent(
    "HandPointerPress", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerPressReleaseEvent = EventManager.RegisterRoutedEvent(
    "HandPointerPressRelease", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerGripEvent = EventManager.RegisterRoutedEvent(
    "HandPointerGrip", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerGripReleaseEvent = EventManager.RegisterRoutedEvent(
    "HandPointerGripRelease", RoutingStrategy.Bubble, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerGotCaptureEvent = EventManager.RegisterRoutedEvent(
    "HandPointerGotCapture", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent HandPointerLostCaptureEvent = EventManager.RegisterRoutedEvent(
    "HandPointerLostCapture", RoutingStrategy.Direct, typeof(EventHandler<HandPointerEventArgs>), typeof(KinectRegion));

public static readonly RoutedEvent QueryInteractionStatusEvent = EventManager.RegisterRoutedEvent(
    "QueryInteractionStatus", RoutingStrategy.Bubble, typeof(EventHandler<QueryInteractionStatusEventArgs>), typeof(KinectRegion));

InitializeKinectButtonBase函数设置按钮的默认行为:

private void InitializeKinectButtonBase()
{
    KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress);
    KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured);
    KinectRegion.AddHandPointerPressReleaseHandler(this, this.OnHandPointerPressRelease);
    KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture);
    KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
    KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave);

    KinectRegion.SetIsPressTarget(this, true);
}

您可以在 UI 中实际定义按钮的任何位置执行相同操作。钩住HandPointerEnterHandPointerLeave处理程序,然后您可以计算用户将手形光标移入和移出该区域的次数。

于 2013-04-08T16:30:14.437 回答
0

不确定这些是否是自定义控件,但是我非常肯定大多数控件应该带有鼠标输入事件或能够扩展它。

<Button Tag="Test" MouseEnter="enterMethod">

并且只需让您的方法为每次鼠标悬停增加一个变量。

于 2013-04-06T09:59:38.673 回答