c# - Kinect 检测指针悬停在 tilebutton 上

标签 c# visual-studio kinect

我正在尝试检测 tilebutton 上的悬停(如 onmouseover),但它必须是内置指针。我找不到事件中的构建,但我已经尝试过了,但它给了我一个异常(对匹配指定绑定(bind)约束的类型 'Microsoft.Kinect.Toolkit.Controls.KinectUserViewer' 的构造函数的调用引发了异常'

XAML 给出异常:

 <k:KinectUserViewer k:KinectRegion.KinectRegion="{Binding ElementName=kinectRegion}"     HorizontalAlignment="Center" Height="150" VerticalAlignment="Top" Width="150"     Canvas.Left="820"/>
        <k:KinectRegion KinectSensor="{Binding Kinect, ElementName=kinectSensorChooser1}"     Height="919" Width="1920" x:Name="kinectRegion" Canvas.Top="151">

按钮由 forloop 自动创建。

CS:

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 MainWindow()
    {
        InitializeComponent();

        KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
        KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave);
 ....
 private void OnHandPointerEnter(object sender, HandPointerEventArgs handPointerEventArgs)
    {
        this.Close();//Trying to see if it works
    }
    private void OnHandPointerLeave(object sender, HandPointerEventArgs handPointerEventArgs)
    {
        this.Close();//Trying to see if it works
    }

我试过的来自这个链接: Hand over button event in Kinect SDK 1.7

但是,如果我删除前两行 (public static),程序可以运行,但不会检测到悬停。对于这些行,它会抛出异常。

基本上我首先尝试的是检测悬停然后关闭程序(让我知道它是否有效)。

感谢帮助

最佳答案

您的版本

KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave);

第一个参数'this'表示一个表单

但它必须是一个“KinectTileButton”

我的版本 - 它有效。

KinectRegion.AddHandPointerEnterHandler(this.KinectTileButtonName, this.OnHandPointerEnter);
KinectRegion.AddHandPointerLeaveHandler(this.KinectTileButtonName, this.OnHandPointerLeave);

关于c# - Kinect 检测指针悬停在 tilebutton 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16563484/

相关文章:

windows - 比较 Windows 和 Mac OS X 作为开发环境

c# - MSTest.exe 给出程序集或模块未找到警告

javascript - 如何在asp.net中添加动态javascript警报框?

c# - 如何将 Kinect v2 保留的 WriteableBitmap 对象保存到 Windows 应用商店应用程序中的图像文件

c# - 在其他程序中人为生成关键事件

c# - 在 C# 中创建单项列表的快捷方式

c# - 如何使用 C# 读取 Microsoft Edge 历史记录

c# - 为什么我不能像添加服务引用那样使用任务生成代理?

c# - 如何在非表单应用程序中生成击键

c# - 在 3D Kinect 中识别手语