首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kinect 2 onHover单击

Kinect 2 onHover单击
EN

Stack Overflow用户
提问于 2016-02-26 10:06:22
回答 1查看 482关注 0票数 0

我正在为WPF (Kinect 2)编写Kinect应用程序。我使用KinectRegion来触发一些按钮,但是我想在悬停而不是单击时触发这些按钮。实现这一目标的最佳途径是什么?我试过MouseEnter和MouseLeave,但没有运气。我的目标是当用户悬停在一个按钮上,播放一个动画,然后在2秒后点击按钮。我很感激你的帮助!

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-27 08:33:09

更新-

为了寻找解决这个问题的多种方法,我想出了一个解决方案:

我们在加载窗口时执行代码。

代码语言:javascript
复制
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 )。你可以根据你的项目四处游玩。最后,我们用以下代码隐藏鼠标指针:

代码语言:javascript
复制
this.Cursor = Cursors.None;

现在我们可以使用OnMouseEnter和OnMouseLeave事件.我希望这对任何有此问题的人都有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35648753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档