Reputation: 2142
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!
Upvotes: 0
Views: 1630
Reputation: 934
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;
}
}
Upvotes: 2
Reputation: 1857
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.
Upvotes: 0