这是我发现的-
1) 光标图像和大小- 这两个示例都使用 Microsoft.Kinect.Toolkit.Controls 项目,该项目定义了这些示例中使用的自定义控件(KinectTileButton、KinectScrollViwer、KinectRegion 等)。Kinect 光标图像和大小在 Microsoft.Kinect.Toolkit.Controls ->Themes->Generic.xaml 中定义为资源。在文件中搜索以下内容 -
<Style TargetType="{x:Type local:KinectCursor}">
您可以根据需要进行修改。无法直接从 UI 中找到任何公开的属性/挂钩来控制它。
2) Tile Button 上的 Grip 事件- Kinect Button 支持各种事件,这些事件可以订阅并根据您的需要进行操作。在 Kinect SDK 1.7 中查看此
移交按钮事件
3) 将光标图像更改为 Grip on Tile Button - Microsoft.Kinect.Toolkit.Controls 项目使用 KinectCursorVisualizer.cs 和 KinectCursor.cs 在 UI 上呈现虚拟手形光标。Open Hand/Grip 视觉状态通过 KinectCursor.cs 中定义的此依赖属性进行控制。
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
"IsOpen",
typeof(bool),
typeof(KinectCursor),
new UIPropertyMetadata(true, (o, args) => ((KinectCursor)o).EnsureVisualState()));
快速查找有关 IsOpen 属性的所有引用表明设置此属性的唯一位置是 KinectCursorVisualizer.cs-> OnHandPointersUpdated 方法。线 - 229
// Set open state
cursor.IsOpen = !pointer.IsInGripInteraction;
这个 pointer.IsInGripInteraction 属性设置在 KinectAdapter.cs 第 678 行
handPointer.IsInGripInteraction = newIsInGripInteraction;
如果您查看这一行上方的代码,您会发现只有在目标元素定义了 QueryInteractionStatusHandler 并将 args.Handled 、 args.IsInGripInteraction 属性设置为 true 时,此属性才设置为 true。
由于 KinectScrollViewer 已定义此处理程序,因此您会看到一个夹点图像。
private void InitializeKinectScrollViewer()
{
KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured);
KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture);
KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
KinectRegion.AddHandPointerMoveHandler(this, this.OnHandPointerMove);
KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress);
KinectRegion.AddHandPointerGripHandler(this, this.OnHandPointerGrip);
KinectRegion.AddHandPointerGripReleaseHandler(this, this.OnHandPointerGripRelease);
//This is the QueryInteractionStatusHandler
KinectRegion.AddQueryInteractionStatusHandler(this, this.OnQueryInteractionStatus);
KinectRegion.SetIsGripTarget(this, true);
this.scrollMoveTimer.Tick += this.OnScrollMoveTimerTick;
this.scrollViewerInertiaScroller.SlowEnoughForSelectionChanged += this.OnSlowEnoughForSelectionChanged;
// Create KinectRegion binding
this.kinectRegionBinder = new KinectRegionBinder(this);
this.kinectRegionBinder.OnKinectRegionChanged += this.OnKinectRegionChanged;
}
但 KinectTileButton(扩展 KinectButtonBase)没有定义此处理程序
private void InitializeKinectButtonBase()
{
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);
}
如何定义这个处理程序?- 简单地将以下内容添加到您的 UI。可以添加到构造函数
//Add the handler
KinectRegion.AddQueryInteractionStatusHandler(kinectButton, OnQuery);
定义处理程序
//Variable to track GripInterationStatus
bool isGripinInteraction = false;
private void OnQuery(object sender, QueryInteractionStatusEventArgs handPointerEventArgs)
{
//If a grip detected change the cursor image to grip
if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.Grip)
{
isGripinInteraction = true;
handPointerEventArgs.IsInGripInteraction = true;
}
//If Grip Release detected change the cursor image to open
else if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.GripRelease)
{
isGripinInteraction = false;
handPointerEventArgs.IsInGripInteraction = false;
}
//If no change in state do not change the cursor
else if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.None)
{
handPointerEventArgs.IsInGripInteraction = isGripinInteraction;
}
handPointerEventArgs.Handled = true;
}
您可能需要根据您的要求进行调整。快乐的 Kinecting :)