using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit;
using Microsoft.Kinect.Toolkit.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
namespace WpfApplication1
{
public partial class MainMenu : Page
{
#region "Kinect"
private readonly KinectSensorChooser sensorChooser;
#endregion
public MainMenu()
{
this.InitializeComponent();
if (Generics.GlobalKinectSensorChooser == null)
{
// initialize the sensor chooser and UI
this.sensorChooser = new KinectSensorChooser();
this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
this.sensorChooser.Start();
Generics.GlobalKinectSensorChooser = this.sensorChooser;
}
else
{ // initialize the sensor chooser and UI
this.sensorChooser = new KinectSensorChooser();
this.sensorChooser = Generics.GlobalKinectSensorChooser;
this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
this.sensorChooserUi.KinectSensorChooser = sensorChooser;
}
// Bind the sensor chooser's current sensor to the KinectRegion
var regionSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);
}
///
#region "New Kinect Gesture"
///
/// Called when the KinectSensorChooser gets a new sensor
///
///
Inside the Navigated Pages
When you navigate from the Manu Page to other pages or from one page to another. You will need to get the sensorchooser from the static property that we created earlier. using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit;
using Microsoft.Kinect.Toolkit.Controls;
namespace WpfApplication1
{
public partial class Game1 : Page
{
#region "Kinect"
private readonly KinectSensorChooser sensorChooser;
//
#endregion
public Game1()
{
this.InitializeComponent();
// initialize the sensor chooser and UI
this.sensorChooser = new KinectSensorChooser();
//Assign the sensor chooser with the sensor chooser from the mainwindow.
//We are reusing the sensorchoosing declared in the first window that can in contact with kinect
this.sensorChooser = Generics.GlobalKinectSensorChooser;
//subscribe to the sensorChooserOnKinectChanged event
this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
//Assign Kinect Sensorchooser to the sensorchooser we got from our static class
this.sensorChooserUi.KinectSensorChooser = sensorChooser;
// Bind the sensor chooser's current sensor to the KinectRegion
var regionSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);
}
///
#region "New Kinect Gesture"
///
/// Execute shutdown tasks
///
///
MainMenu Xaml Page
<Page x:Class="WpfApplication1.MainMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:Microsoft.Samples.Kinect.ControlsBasics"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:k="http://schemas.microsoft.com/kinect/2013"
xmlns:tk="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit"
mc:Ignorable="d"
MinWidth="500"
MinHeight="700"
FontFamily="Segoe UI"
Title="Page" Width="1039.2" Height="656">
<Grid Margin="0,0,0.2,0" Height="700" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="10,0,841,20">
<Image HorizontalAlignment="Left" VerticalAlignment="Bottom" Source="Images\Logo.png" Stretch="None" Margin="0 0 0 4"/>
<k:KinectUserViewer k:KinectRegion.KinectRegion="{Binding ElementName=kinectRegion}" Height="100" HorizontalAlignment="Center" VerticalAlignment="Top" />
</Grid>
<k:KinectRegion x:Name="kinectRegion" Margin="0,143,0,0" Grid.RowSpan="2">
<Grid x:Name="kinectRegionGrid" Margin="10,20,160,19.8">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="170" />
</Grid.RowDefinitions>
<WrapPanel VerticalAlignment="Center" x:Name="wrapPanel" Orientation="Vertical" >
<k:KinectTileButton Content="GAME1" Height="348" Width="314" Background="#FFF52222" FontSize="48" Click="KinectTileButton_Click_1" />
<k:KinectTileButton Content="GAME2" Height="350" Width="296" Background="#FF17CB6A" FontSize="48" Click="KinectTileButton_Click_2" />
<k:KinectTileButton Content="GAME3" Height="348" Width="259" Background="#FFEDE610" FontSize="48" Click="KinectTileButton_Click_3" />
</WrapPanel>
</Grid>
</k:KinectRegion>
<Image HorizontalAlignment="Left" VerticalAlignment="Bottom" Source="Images/logo_comp.jpg" Stretch="None" Margin="762,0,0,0.2"/>
<tk:KinectSensorChooserUI HorizontalAlignment="Center" VerticalAlignment="Top" x:Name="sensorChooserUi" Margin="461,10,538,0" />
</Grid>
</Page>