//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ namespace Microsoft.Samples.Kinect.KinectExplorer { using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using Microsoft.Kinect; using Microsoft.Samples.Kinect.WpfViewers; /// /// Interaction logic for KinectWindow.xaml. /// public partial class KinectWindow : Window { public static readonly DependencyProperty KinectSensorProperty = DependencyProperty.Register( "KinectSensor", typeof(KinectSensor), typeof(KinectWindow), new PropertyMetadata(null)); private readonly KinectWindowViewModel viewModel; /// /// Initializes a new instance of the KinectWindow class, which provides access to many KinectSensor settings /// and output visualization. /// public KinectWindow() { this.viewModel = new KinectWindowViewModel(); // The KinectSensorManager class is a wrapper for a KinectSensor that adds // state logic and property change/binding/etc support, and is the data model // for KinectDiagnosticViewer. this.viewModel.KinectSensorManager = new KinectSensorManager(); Binding sensorBinding = new Binding("KinectSensor"); sensorBinding.Source = this; BindingOperations.SetBinding(this.viewModel.KinectSensorManager, KinectSensorManager.KinectSensorProperty, sensorBinding); // Attempt to turn on Skeleton Tracking for each Kinect Sensor this.viewModel.KinectSensorManager.SkeletonStreamEnabled = true; this.DataContext = this.viewModel; InitializeComponent(); } public KinectSensor KinectSensor { get { return (KinectSensor)GetValue(KinectSensorProperty); } set { SetValue(KinectSensorProperty, value); } } public void StatusChanged(KinectStatus status) { this.viewModel.KinectSensorManager.KinectSensorStatus = status; } private void Swap_Executed(object sender, ExecutedRoutedEventArgs e) { Grid colorFrom = null; Grid depthFrom = null; if (this.MainViewerHost.Children.Contains(this.ColorVis)) { colorFrom = this.MainViewerHost; depthFrom = this.SideViewerHost; } else { colorFrom = this.SideViewerHost; depthFrom = this.MainViewerHost; } colorFrom.Children.Remove(this.ColorVis); depthFrom.Children.Remove(this.DepthVis); colorFrom.Children.Insert(0, this.DepthVis); depthFrom.Children.Insert(0, this.ColorVis); } public KinectSkeleton ks = new KinectSkeleton(); private void Calibrate_Click(object sender, RoutedEventArgs e) { ks.setcurrentdt(); } private void AngleDifference_Checked(object sender, RoutedEventArgs e) { ks.is_checked = true; } private void AngleDifference_Unchecked(object sender, RoutedEventArgs e) { ks.is_checked = false; } } } /// /// A ViewModel for a KinectWindow. /// public class KinectWindowViewModel : DependencyObject { public static readonly DependencyProperty KinectSensorManagerProperty = DependencyProperty.Register( "KinectSensorManager", typeof(KinectSensorManager), typeof(KinectWindowViewModel), new PropertyMetadata(null)); public KinectSensorManager KinectSensorManager { get { return (KinectSensorManager)GetValue(KinectSensorManagerProperty); } set { SetValue(KinectSensorManagerProperty, value); } } } } namespace Microsoft.Samples.Kinect.WpfViewers { using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using Microsoft.Kinect; using System.Data; using System.Windows.Media.Media3D; using System.Globalization; /// /// This control is used to render a player's skeleton. /// If the ClipToBounds is set to "false", it will be allowed to overdraw /// it's bounds. /// public class KinectSkeleton : Control { public bool is_checked=false; public DataTable x = new DataTable(); public DataTable y = new DataTable(); protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); var currentSkeleton = this.Skeleton; // Don't render if we don't have a skeleton, or it isn't tracked if (drawingContext == null || currentSkeleton == null || currentSkeleton.TrackingState == SkeletonTrackingState.NotTracked) { return; } // Displays a gradient near the edge of the display where the skeleton is leaving the screen this.RenderClippedEdges(drawingContext); switch (currentSkeleton.TrackingState) { case SkeletonTrackingState.PositionOnly: if (this.ShowCenter) { drawingContext.DrawEllipse( this.centerPointBrush, null, this.Center, BodyCenterThickness * this.ScaleFactor, BodyCenterThickness * this.ScaleFactor); } break; case SkeletonTrackingState.Tracked: // here i defined the DataTables if (is_checked == false) { //fill data table x with value a } else { //fill data table x with value b } break; } } public void setcurrentdt() { //fill empty datatable "y" with filled one "x" y = x.Copy(); } } }
复选框的xaml代码:
Kinect Explorer FPS FPS
ViewModel类:
public class ViewModel { public bool IsChecked { get; set; } public bool is_clicked { get; set; } }