我正在为WPF (Kinect 2)编写Kinect应用程序。我使用KinectRegion来触发一些按钮,但是我想在悬停而不是单击时触发这些按钮。实现这一目标的最佳途径是什么?我试过MouseEnter和MouseLeave,但没有运气。我的目标是当用户悬停在一个按钮上,播放一个动画,然后在2秒后点击按钮。我很感激你的帮助!
<k:KinectRegion x:Name="kinectRegion" >
<Grid Background="White" Name="gridTest">
<k:KinectUserViewer Height="400" Width="300" HorizontalAlignment="Center" VerticalAlignment="Top" DefaultUserColor="#FFF93636" EngagedUserColor="#FF395913" />
<Button Name="buttonStartSpel" Width="400" Height="200" Margin="0,800,0,0" VerticalAlignment="Top" HorizontalAlignment="Center" Content="Start het spel" Style="{StaticResource KinectCustomButton}" MouseEnter="buttonStartSpel_MouseEnter" MouseLeave="buttonStartSpel_MouseLeave"></Button>
</Grid>
</k:KinectRegion>发布于 2016-06-27 08:33:09
更新-
为了寻找解决这个问题的多种方法,我想出了一个解决方案:
我们在加载窗口时执行代码。
void KinectPointerPointSample_Loaded(object sender, RoutedEventArgs e)
{
// Listen to Kinect pointer events
KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread();
kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved;
}
private void kinectCoreWindow_PointerMoved(object sender, KinectPointerEventArgs args)
{
KinectPointerPoint kinectPointerPoint = args.CurrentPoint;
bool isEngaged = kinectPointerPoint.Properties.IsEngaged;
if (isEngaged)
{
System.Drawing.Point mousePt = new System.Drawing.Point((int)(kinectPointerPoint.Position.X * kinectRegion.ActualWidth - 80), (int)(kinectPointerPoint.Position.Y * kinectRegion.ActualHeight));
System.Windows.Forms.Cursor.Position = mousePt;
}
}注意到鼠标指针没有完全相同的位置指针,我已经测试了阴性的结果。这就是为什么我把鼠标指针稍微左转到手指针(确切地说,是80 pixs )。你可以根据你的项目四处游玩。最后,我们用以下代码隐藏鼠标指针:
this.Cursor = Cursors.None;现在我们可以使用OnMouseEnter和OnMouseLeave事件.我希望这对任何有此问题的人都有帮助。
https://stackoverflow.com/questions/35648753
复制相似问题