Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display the kinect status-Connected or disconnected and the Device Connection ID. Connection ID is getting displayed,but Status is not getting displayed in Textblock My code is-
mainwindow.xaml.cs-
public partial class MainWindow : Window
{

KinectSensor sensor;
private MainWindowViewModel viewModel;
public MainWindow()
{

InitializeComponent();
this.Loaded += MainWindow_Loaded;
this.viewModel = new MainWindowViewModel();
this.DataContext = this.viewModel;

}


void KinectSensors_StatusChanged(object sender, StatusChangedEventArgs e)
{

switch (e.Status)
{
case KinectStatus.Connected:
txtBlckStatus.Text = "Connected";


break;
case KinectStatus.Disconnected:
txtBlckStatus.Text = "Disconnected";

break;

}
}

void MainWindow_Loaded(object sender, RoutedEventArgs e)
{


if (KinectSensor.KinectSensors.Count > 0)
{
this.sensor = KinectSensor.KinectSensors[0];
KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged;

this.StartSensor();
this.sensor.ColorStream.Enable();
this.sensor.DepthStream.Enable();
this.sensor.SkeletonStream.Enable();
}
else
{
MessageBox.Show("No Sensor Connected!!");
this.Close();
}

}

private void StartSensor()
{
if(this.sensor!=null && !this.sensor.IsRunning)
{
this.sensor.Start();
SetKinectInfo();

}
}


private void SetKinectInfo()
{
if(this.sensor!=null)
{
this.viewModel.ConnectionID = this.sensor.DeviceConnectionId;
}
}

}

mainwindow.xaml

<window x:class="KinectInfoBox.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<grid>
<grid>
<grid.rowdefinitions>
<rowdefinition>
<rowdefinition>
<rowdefinition>

<grid.columndefinitions>
<columndefinition> <columndefinition>
<textblock grid.row="0" grid.column="0" text="Status:">
<textblock grid.row="0" grid.column="1" x:name="txtBlckStatus">
<textblock grid.row="1" grid.column="0" text="Connection ID">
<textblock grid.row="1" grid.column="1" text="{Binding ConnectionID}">





mainwindowviewmodel.cs--to display the changing connection id

namespace KinectInfoBox
{
public class MainWindowViewModel:INotifyPropertyChanged
{
private string _connectionIDValue;
public string ConnectionID
{
get { return _connectionIDValue; }
set
{
if(this._connectionIDValue!=value)
{
this._connectionIDValue = value;
this.OnNotifyPropertyChange("ConnectionID");
}
}
}
public void OnNotifyPropertyChange(string propertyName)
{
if(this.PropertyChanged!=null)
{
this.PropertyChanged.Invoke(this,newPropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
Posted
Comments
[no name] 3-May-14 8:17am    
Did you bother debugging your code? Do you really expect people to read this? Your code would not compile mostly because your main window does not contain anything. Why are you setting your DataContext to your ViewModel but then setting control properties directly in the window code behind?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900