2

我正在尝试检测 tilebutton 上的悬停(如 onmouseover),但它必须是内置指针。我找不到内置事件,我已经尝试过了,但它给了我一个异常(在类型'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
    }

我尝试过的来自此链接: Kinect SDK 1.7 中的移交按钮事件

但是,如果我删除前两行(公共静态),程序可以工作,但未检测到悬停。有了这些行,它会抛出异常。

基本上我首先尝试的是检测悬停,然后关闭程序(如果它有效,让我有一个好主意)。

谢谢您的帮助

4

1 回答 1

1

您的版本

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

第一个参数“this”表示表单

但它必须是“KinectTileButton”

我的版本 - 它有效。

KinectRegion.AddHandPointerEnterHandler(this.KinectTileButtonName, this.OnHandPointerEnter);
KinectRegion.AddHandPointerLeaveHandler(this.KinectTileButtonName, this.OnHandPointerLeave);
于 2013-10-22T16:16:35.797 回答