ADD : Avancement Kinect Connection

ui-window
lobroda 1 year ago
parent dc409d9944
commit 26d8bba025

@ -47,12 +47,6 @@
<Compile Include="KinectManager.cs" /> <Compile Include="KinectManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KinectSensorStreams\KinectSensorStreams.csproj">
<Project>{7004f18c-b43f-4111-a7fa-d803217d5474}</Project>
<Name>KinectSensorStreams</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>

@ -1,6 +1,7 @@
using Microsoft.Kinect; using Microsoft.Kinect;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Resources; using System.Resources;
using System.Security.Policy; using System.Security.Policy;
@ -12,7 +13,7 @@ namespace KinectConnection
public class KinectManager public class KinectManager
{ {
KinectManager() public KinectManager()
{ {
this.kinectSensor = KinectSensor.GetDefault(); this.kinectSensor = KinectSensor.GetDefault();
} }
@ -21,17 +22,41 @@ namespace KinectConnection
public KinectSensor kinectSensor; public KinectSensor kinectSensor;
public bool Status; public bool Status;
public string StatusText; public event PropertyChangedEventHandler PropertyChanged;
private string statusText;
public string StatusText
{
get
{
return this.statusText;
}
set
{
if (this.statusText != value)
{
this.statusText = value;
if(this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("StatusText"));
}
}
}
}
// methods // methods
public void StartSensor() public void StartSensor()
{ {
this.kinectSensor.Open(); this.kinectSensor.Open();
this.kinectSensor.IsAvailableChanged += this.KinectSensor_IsAvailableChanged;
} }
public void StopSensor() public void StopSensor()
{ {
this.kinectSensor.IsAvailableChanged -= this.KinectSensor_IsAvailableChanged;
this.kinectSensor.Close(); this.kinectSensor.Close();
} }

@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:KinectSensorStreams" xmlns:local="clr-namespace:KinectSensorStreams"
StartupUri="MainWindow.xaml"> StartupUri="View/MainWindow.xaml">
<Application.Resources> <Application.Resources>
</Application.Resources> </Application.Resources>

@ -1,4 +1,7 @@
using System; using KinectSensorStreams.View;
using KinectSensorStreams.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Data; using System.Data;

@ -11,6 +11,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Kinect" Version="2.0.1410.19000" /> <PackageReference Include="Microsoft.Kinect" Version="2.0.1410.19000" />
</ItemGroup> </ItemGroup>
@ -20,4 +21,8 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
</Project> <ItemGroup>
<ProjectReference Include="..\KinectConnection\KinectConnection.csproj" />
</ItemGroup>
</Project>

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:CommunityToolkit.Mvvm.Input;assembly=CommunityToolkit.Mvvm"
xmlns:local="clr-namespace:KinectSensorStreams.View" xmlns:local="clr-namespace:KinectSensorStreams.View"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="450" Width="800">
@ -29,7 +30,7 @@
Height="30" Height="30"
Fill="{Binding Path=EllipseColor}" Fill="{Binding Path=EllipseColor}"
Grid.Column="1"/> Grid.Column="1"/>
<TextBlock Text="Running" <TextBlock Text="{Binding KinectManager.StatusText}"
VerticalAlignment="Center" VerticalAlignment="Center"
FontWeight="Bold" FontWeight="Bold"
Grid.Column="3"/> Grid.Column="3"/>

@ -28,13 +28,19 @@ namespace KinectSensorStreams.View
#region Constructor #region Constructor
public MainWindow(MainWindowVM mainWindowVM) public MainWindow()
{ {
MainWindowVM = mainWindowVM; MainWindowVM = new MainWindowVM();
InitializeComponent(); InitializeComponent();
DataContext = MainWindowVM; DataContext = MainWindowVM;
} }
public override void BeginInit()
{
base.BeginInit();
MainWindowVM.StartCommand.Execute(null);
}
#endregion #endregion
} }
} }

@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using KinectConnection;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
@ -6,6 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
namespace KinectSensorStreams.ViewModel namespace KinectSensorStreams.ViewModel
{ {
@ -13,11 +15,13 @@ namespace KinectSensorStreams.ViewModel
{ {
#region Properties #region Properties
public Color EllipseColor { get; set; } public System.Windows.Media.Brush EllipseColor { get; set; }
public string KinectStateText { get; set; }
public ICommand StartCommand { get; set; } public ICommand StartCommand { get; set; }
public ICommand StopCommand { get; set; } public KinectManager KinectManager { get; set; }
#endregion #endregion
@ -25,8 +29,9 @@ namespace KinectSensorStreams.ViewModel
public MainWindowVM() public MainWindowVM()
{ {
EllipseColor = new SolidColorBrush(Colors.Green);
KinectManager = new KinectManager();
StartCommand = new RelayCommand(Start); StartCommand = new RelayCommand(Start);
StopCommand = new RelayCommand(Stop);
} }
#endregion #endregion
@ -35,14 +40,8 @@ namespace KinectSensorStreams.ViewModel
private void Start() private void Start()
{ {
KinectManager.kinectSensor.Open();
EllipseColor = Color.Green; EllipseColor = new SolidColorBrush(Colors.Green);
}
private void Stop()
{
EllipseColor = Color.Red;
} }
#endregion #endregion

Loading…
Cancel
Save