2016-02-26 59 views
0

我正在爲WPF(Kinect 2)開發Kinect應用程序。我正在使用KinectRegion觸發一些按鈕,但我想觸發懸停按鈕而不是點擊按鈕。達到這個目標的最好方法是什麼?我已經用MouseEnter和MouseLeave嘗試過,但沒有運氣。我的目標是當用戶將鼠標懸停在按鈕上時播放動畫,然後在2秒後點擊按鈕。我將不勝感激任何幫助!Kinect 2 onHover click

<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> 
+0

我會建議創建自己的按鈕繼承的用戶控件,並管理你的懸停動畫以及點擊事件那裏只有 –

+0

謝謝,我今天會試一試 – Manuel

+0

你有解決我們的問題嗎? – Franckentien

回答

0

更新 -

尋找多種方法來解決這個問題,我想出了這個解決方案:

我們執行的窗口加載代碼。

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個像素)。您可以根據自己的項目玩耍。最後,我們隱藏用下面的代碼將鼠標指針:

this.Cursor = Cursors.None; 

現在我們可以使用OnMouseEnter在和OnMouseLeave在事件......我希望這有助於任何人有這個問題。