Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .cs code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using Microsoft.Kinect;
- namespace WpfApplicationKinectSkeletonTracking
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- ///
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
- }
- void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- KinectSensor oldSensor = (KinectSensor)e.OldValue;
- StopKinect(oldSensor);
- KinectSensor newSensor = (KinectSensor)e.NewValue;
- newSensor.DepthStream.Enable();
- newSensor.SkeletonStream.Enable();
- try
- { newSensor.Start(); }
- catch (System.IO.IOException)
- { kinectSensorChooser1.AppConflictOccurred(); }
- }
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- StopKinect(kinectSensorChooser1.Kinect);
- }
- void StopKinect(KinectSensor sensor)
- {
- if (sensor != null)
- {
- sensor.Stop();
- sensor.AudioSource.Stop();
- }
- }
- }
- }
- .xaml code:
- <Window x:Class="WpfApplicationKinectSkeletonTracking.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="350" Width="745" xmlns:my="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" Closing="Window_Closing" Loaded="Window_Loaded">
- <Grid Width="699">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="613*" />
- <ColumnDefinition Width="86*" />
- </Grid.ColumnDefinitions>
- <my:KinectDepthViewer HorizontalAlignment="Left" Margin="30,12,0,0" Name="kinectDepthViewer1" VerticalAlignment="Top" Width="320" Height="240" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}" />
- <my:KinectSensorChooser HorizontalAlignment="Left" Margin="192,63,0,0" Name="kinectSensorChooser1" Width="328" Height="181" VerticalAlignment="Top" />
- <my:KinectSkeletonViewer HorizontalAlignment="Left" Margin="379,12,0,0" Name="kinectSkeletonViewer1" VerticalAlignment="Top" Width="320" Height="240" Grid.ColumnSpan="2" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}" />
- </Grid>
- </Window>
- Dependencies(references) added:
- Microsoft.kinect.dll - found in programfiles/microsoftsdks/kinect/v1.8/assemblies
- Microsoft.kinect - found in .NET tab
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement