From 26d8bba025c5f7bb596e222718c5541c586b4ea1 Mon Sep 17 00:00:00 2001 From: lobroda Date: Mon, 8 Jan 2024 19:32:49 +0100 Subject: [PATCH] ADD : Avancement Kinect Connection --- KinectConnection/KinectConnection.csproj | 6 ---- KinectConnection/KinectManager.cs | 31 +++++++++++++++++-- KinectSensorStreams/App.xaml | 2 +- KinectSensorStreams/App.xaml.cs | 5 ++- .../KinectSensorStreams.csproj | 7 ++++- KinectSensorStreams/View/MainWindow.xaml | 3 +- KinectSensorStreams/View/MainWindow.xaml.cs | 10 ++++-- KinectSensorStreams/ViewModel/MainWindowVM.cs | 21 ++++++------- 8 files changed, 59 insertions(+), 26 deletions(-) diff --git a/KinectConnection/KinectConnection.csproj b/KinectConnection/KinectConnection.csproj index 5d284f2..7083fc9 100644 --- a/KinectConnection/KinectConnection.csproj +++ b/KinectConnection/KinectConnection.csproj @@ -47,12 +47,6 @@ - - - {7004f18c-b43f-4111-a7fa-d803217d5474} - KinectSensorStreams - - diff --git a/KinectConnection/KinectManager.cs b/KinectConnection/KinectManager.cs index bd7c0d6..d234027 100644 --- a/KinectConnection/KinectManager.cs +++ b/KinectConnection/KinectManager.cs @@ -1,6 +1,7 @@ using Microsoft.Kinect; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Resources; using System.Security.Policy; @@ -12,7 +13,7 @@ namespace KinectConnection public class KinectManager { - KinectManager() + public KinectManager() { this.kinectSensor = KinectSensor.GetDefault(); } @@ -21,17 +22,41 @@ namespace KinectConnection public KinectSensor kinectSensor; 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 public void StartSensor() { this.kinectSensor.Open(); + this.kinectSensor.IsAvailableChanged += this.KinectSensor_IsAvailableChanged; } public void StopSensor() { + this.kinectSensor.IsAvailableChanged -= this.KinectSensor_IsAvailableChanged; this.kinectSensor.Close(); } diff --git a/KinectSensorStreams/App.xaml b/KinectSensorStreams/App.xaml index ff0d335..e0a156d 100644 --- a/KinectSensorStreams/App.xaml +++ b/KinectSensorStreams/App.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:KinectSensorStreams" - StartupUri="MainWindow.xaml"> + StartupUri="View/MainWindow.xaml"> diff --git a/KinectSensorStreams/App.xaml.cs b/KinectSensorStreams/App.xaml.cs index c992a8e..d36007b 100644 --- a/KinectSensorStreams/App.xaml.cs +++ b/KinectSensorStreams/App.xaml.cs @@ -1,4 +1,7 @@ -using System; +using KinectSensorStreams.View; +using KinectSensorStreams.ViewModel; +using Microsoft.Extensions.DependencyInjection; +using System; using System.Collections.Generic; using System.Configuration; using System.Data; diff --git a/KinectSensorStreams/KinectSensorStreams.csproj b/KinectSensorStreams/KinectSensorStreams.csproj index ed8dc9f..37e7391 100644 --- a/KinectSensorStreams/KinectSensorStreams.csproj +++ b/KinectSensorStreams/KinectSensorStreams.csproj @@ -11,6 +11,7 @@ + @@ -20,4 +21,8 @@ - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/KinectSensorStreams/View/MainWindow.xaml b/KinectSensorStreams/View/MainWindow.xaml index 8f7107c..a65eb0b 100644 --- a/KinectSensorStreams/View/MainWindow.xaml +++ b/KinectSensorStreams/View/MainWindow.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> @@ -29,7 +30,7 @@ Height="30" Fill="{Binding Path=EllipseColor}" Grid.Column="1"/> - diff --git a/KinectSensorStreams/View/MainWindow.xaml.cs b/KinectSensorStreams/View/MainWindow.xaml.cs index c60c206..8a0e093 100644 --- a/KinectSensorStreams/View/MainWindow.xaml.cs +++ b/KinectSensorStreams/View/MainWindow.xaml.cs @@ -28,13 +28,19 @@ namespace KinectSensorStreams.View #region Constructor - public MainWindow(MainWindowVM mainWindowVM) + public MainWindow() { - MainWindowVM = mainWindowVM; + MainWindowVM = new MainWindowVM(); InitializeComponent(); DataContext = MainWindowVM; } + public override void BeginInit() + { + base.BeginInit(); + MainWindowVM.StartCommand.Execute(null); + } + #endregion } } diff --git a/KinectSensorStreams/ViewModel/MainWindowVM.cs b/KinectSensorStreams/ViewModel/MainWindowVM.cs index c47c10e..5f5b5c4 100644 --- a/KinectSensorStreams/ViewModel/MainWindowVM.cs +++ b/KinectSensorStreams/ViewModel/MainWindowVM.cs @@ -1,4 +1,5 @@ using CommunityToolkit.Mvvm.Input; +using KinectConnection; using System; using System.Collections.Generic; using System.Drawing; @@ -6,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; +using System.Windows.Media; namespace KinectSensorStreams.ViewModel { @@ -13,11 +15,13 @@ namespace KinectSensorStreams.ViewModel { #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 StopCommand { get; set; } + public KinectManager KinectManager { get; set; } #endregion @@ -25,8 +29,9 @@ namespace KinectSensorStreams.ViewModel public MainWindowVM() { + EllipseColor = new SolidColorBrush(Colors.Green); + KinectManager = new KinectManager(); StartCommand = new RelayCommand(Start); - StopCommand = new RelayCommand(Stop); } #endregion @@ -35,14 +40,8 @@ namespace KinectSensorStreams.ViewModel private void Start() { - - EllipseColor = Color.Green; - } - - private void Stop() - { - - EllipseColor = Color.Red; + KinectManager.kinectSensor.Open(); + EllipseColor = new SolidColorBrush(Colors.Green); } #endregion