Kinect SDK 1.7 - How to control WPF elements Inside/outside the Kinect Region

1.6k views Asked by At

I´m trying to work with Kinect SDK 1.7 in WPF and C#.

Is there any option how to control WPF elements - for example WPF button, WPF slider, etc. I cannot find how to do this. When I take a WPF button to Kinect region the KinectPointer doesn´t react with these controls. I thought that this pointer is something like mouse pointer.

Please can you help me, how to do that?

Thank you very much!

2

There are 2 answers

0
Florent Gz On BEST ANSWER

This link might help you to Kinectify your own controllers. The example is about a checkbox, but you can extend it to other controllers as well:

public class MyCheckBox : CheckBox
{
    private static readonly bool IsInDesignMode = DesignerProperties.GetIsInDesignMode(new DependencyObject());
    private HandPointer _capturedHandPointer;

    public MyCheckBox()
    {
        if (!IsInDesignMode)
        {
            Initialise();
        }
    }

    private void Initialise()
    {
        KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress);
        KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured);
        KinectRegion.AddHandPointerPressReleaseHandler(this, this.OnHandPointerPressRelease);
        KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture);
        KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
        KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave);
        KinectRegion.SetIsPressTarget(this, true);
    }
}

private void OnHandPointerLeave(object sender, HandPointerEventArgs e)
{
    if (!KinectRegion.GetIsPrimaryHandPointerOver(this))
    {
        VisualStateManager.GoToState(this, "Normal", true);
    }
}

private void OnHandPointerEnter(object sender, HandPointerEventArgs e)
{
    if (KinectRegion.GetIsPrimaryHandPointerOver(this))
    {
        VisualStateManager.GoToState(this, "MouseOver", true);
    }
}

private void OnHandPointerLostCapture(object sender, HandPointerEventArgs e)
{
    if (_capturedHandPointer == e.HandPointer)
    {
        _capturedHandPointer = null;
        IsPressed = false;
        e.Handled = true;
    }
}

private void OnHandPointerCaptured(object sender, HandPointerEventArgs e)
{
    if (_capturedHandPointer == null)
    {
        _capturedHandPointer = e.HandPointer;
        IsPressed = true;
        e.Handled = true;
    }
}

private void OnHandPointerPress(object sender, HandPointerEventArgs e)
{
    if (_capturedHandPointer == null && e.HandPointer.IsPrimaryUser && e.HandPointer.IsPrimaryHandOfUser)
    {
        e.HandPointer.Capture(this);
        e.Handled = true;
    }
}

private void OnHandPointerPressRelease(object sender, HandPointerEventArgs e)
{
    if (_capturedHandPointer == e.HandPointer)
    {
        if (e.HandPointer.GetIsOver(this))
        {
            OnClick();
            VisualStateManager.GoToState(this, "MouseOver", true);
        }
        else
        {
            VisualStateManager.GoToState(this, "Normal", true);
        }
        e.Handled = true;
    }
}
0
doerig On

KinectPointer is quite different to a normal Mousepointer, it doesn't work with normal WPF Controls out of the box.

please have a look at the Events that are available at the kinect region:

http://msdn.microsoft.com/en-us/library/microsoft.kinect.toolkit.controls.kinectregion_events.aspx

If i'm remembering correctly, the sourcecode for the Kinect Interaction Tookit Controls is included in the SDK, have a look at KinectButtonBase.cs to see how you could develop Kinect-Controls.