private static void CurrentSensorDepthFormatChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { KinectSettingsViewModel ksvm = dependencyObject as KinectSettingsViewModel; if ((null == ksvm) || (null == ksvm.KinectSensorManager) || !(args.NewValue is DepthImageFormat)) { return; } var newMode = (DepthImageFormat)args.NewValue; if ((DepthImageFormat.Undefined == newMode) || (null == ksvm.KinectSensorManager) || !ksvm.KinectSensorManager.DepthStreamEnabled) { ksvm.SelectedDepthMode = DepthMode.Off; } else { ksvm.SelectedDepthMode = (DepthMode)newMode; } }
private static void CurrentSensorSkeletonEnabledChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { KinectSettingsViewModel ksvm = dependencyObject as KinectSettingsViewModel; if ((null == ksvm) || (null == ksvm.KinectSensorManager) || !(args.NewValue is bool)) { return; } var isEnabled = (bool)args.NewValue; if (!isEnabled || (null == ksvm.KinectSensorManager)) { ksvm.SelectedSkeletonMode = SkeletonMode.Off; } else { ksvm.SelectedSkeletonMode = (SkeletonMode)ksvm.KinectSensorManager.SkeletonTrackingMode; } }
// Change handlers private static void CurrentSensorColorEnabledChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { KinectSettingsViewModel ksvm = dependencyObject as KinectSettingsViewModel; if ((null == ksvm) || (null == ksvm.KinectSensorManager) || !(args.NewValue is bool)) { return; } var isEnabled = (bool)args.NewValue; if (!isEnabled || (null == ksvm.KinectSensorManager) || (ColorImageFormat.Undefined == ksvm.KinectSensorManager.ColorFormat)) { ksvm.SelectedColorMode = ColorMode.Off; } else { ksvm.SelectedColorMode = (ColorMode)ksvm.KinectSensorManager.ColorFormat; } }
private static void DepthModeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { KinectSettingsViewModel ksvm = dependencyObject as KinectSettingsViewModel; if ((null == ksvm) || (null == ksvm.KinectSensorManager) || !(args.NewValue is DepthMode)) { return; } var newMode = (DepthMode)args.NewValue; if (DepthMode.Off == newMode) { ksvm.KinectSensorManager.DepthStreamEnabled = false; } else { ksvm.KinectSensorManager.DepthStreamEnabled = true; ksvm.KinectSensorManager.DepthFormat = (DepthImageFormat)newMode; } }
private static void SkeletonModeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { KinectSettingsViewModel ksvm = dependencyObject as KinectSettingsViewModel; if ((null == ksvm) || (null == ksvm.KinectSensorManager) || !(args.NewValue is SkeletonMode)) { return; } var newMode = (SkeletonMode)args.NewValue; if (SkeletonMode.Off == newMode) { ksvm.KinectSensorManager.SkeletonStreamEnabled = false; } else { // Always set the mode ksvm.KinectSensorManager.SkeletonTrackingMode = (SkeletonTrackingMode)newMode; // Are we transitioning from off to on? if (SkeletonMode.Off == (SkeletonMode)args.OldValue) { // If so, enable the Skeleton Stream ksvm.KinectSensorManager.SkeletonStreamEnabled = true; // This may not "take" if there's no skeletal tracking available if (!ksvm.KinectSensorManager.SkeletonStreamEnabled) { // It didn't work - set the SkeletonMode back to Off. // We could use validation or coercion to ensure that the SkeletonMode can't be enabled if there's no ST pipeline available. // Alternately, we could just set ksvm.SelectedSkeletonMode to Off here directly. // However, ListBox and other controls do not respond to property updates that occur during a change // callback of that same property, so we need to post a work item to change this value after we return. ksvm.Dispatcher.BeginInvoke((Action)(() => { ksvm.SelectedSkeletonMode = SkeletonMode.Off; })); } } } }