我正在尝试检测 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/