From 83fbf15916a47829508460612ca650e22982cafa Mon Sep 17 00:00:00 2001
From: MoYue <18168119590@163.com>
Date: Mon, 6 Feb 2023 13:24:00 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BA=95=E9=83=A8=E6=B7=BB=E5=8A=A0=E7=B3=BB?=
=?UTF-8?q?=E7=BB=9F=E7=8A=B6=E6=80=81=E6=A0=8F=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
MonitoringTechnology/Base/StateBackConvert.cs | 35 ++++++++++++++
MonitoringTechnology/MainWindow.xaml | 14 +++++-
.../MonitoringTechnology.csproj | 1 +
.../ViewModels/MainViewModel.cs | 47 ++++++++++++++++++-
.../Views/SystemOperationView.xaml | 4 +-
.../Views/SystemOperationView.xaml.cs | 14 +++---
6 files changed, 104 insertions(+), 11 deletions(-)
create mode 100644 MonitoringTechnology/Base/StateBackConvert.cs
diff --git a/MonitoringTechnology/Base/StateBackConvert.cs b/MonitoringTechnology/Base/StateBackConvert.cs
new file mode 100644
index 0000000..3116823
--- /dev/null
+++ b/MonitoringTechnology/Base/StateBackConvert.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+using System.Windows.Media;
+
+namespace MonitoringTechnology.Base
+{
+ public class StateBackConvert : IValueConverter
+ {
+ public static object ConvertObject;
+
+ object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ Brush background = null;
+ if ((bool)value == true)
+ {
+ background = new SolidColorBrush(Color.FromRgb(0, 255, 127));
+ }
+ else if ((bool)value == false)
+ {
+ background = new SolidColorBrush(Color.FromRgb(255, 0, 0));
+ }
+ return background;
+ }
+
+ object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/MonitoringTechnology/MainWindow.xaml b/MonitoringTechnology/MainWindow.xaml
index 361df71..abfcc7d 100644
--- a/MonitoringTechnology/MainWindow.xaml
+++ b/MonitoringTechnology/MainWindow.xaml
@@ -48,9 +48,10 @@
-
-
+
+
+
@@ -63,6 +64,7 @@
+
@@ -101,6 +103,14 @@
+
+
+
+
+
+
+
+
diff --git a/MonitoringTechnology/MonitoringTechnology.csproj b/MonitoringTechnology/MonitoringTechnology.csproj
index da89f3f..1531308 100644
--- a/MonitoringTechnology/MonitoringTechnology.csproj
+++ b/MonitoringTechnology/MonitoringTechnology.csproj
@@ -154,6 +154,7 @@
+
diff --git a/MonitoringTechnology/ViewModels/MainViewModel.cs b/MonitoringTechnology/ViewModels/MainViewModel.cs
index e1bcb99..34cb9c5 100644
--- a/MonitoringTechnology/ViewModels/MainViewModel.cs
+++ b/MonitoringTechnology/ViewModels/MainViewModel.cs
@@ -7,11 +7,44 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
+using System.Windows.Media;
namespace MonitoringTechnology.ViewModels
{
public class MainViewModel : NotifyPropertyBase
{
+ ///
+ /// 当前蓝牙设备是否已连接
+ ///
+ private string _isConnection;
+
+ public string IsConnection
+ {
+ get { return _isConnection; }
+ set { _isConnection = value; this.RaisePropertyChanged(); }
+ }
+ ///
+ /// 连接标志 -绿色(已连接) / 红色(未连接)
+ ///
+ private SolidColorBrush brush;
+
+ public SolidColorBrush Brush
+ {
+ get { return brush; }
+ set { brush = value;this.RaisePropertyChanged(); }
+ }
+
+ ///
+ /// 蓝牙名称
+ ///
+ private string _lYDevice;
+
+ public string LYDevice
+ {
+ get { return _lYDevice; }
+ set { _lYDevice = value;this.RaisePropertyChanged(); }
+ }
+
private UIElement _mainContent;
@@ -29,8 +62,20 @@ namespace MonitoringTechnology.ViewModels
public MainViewModel()
{
TabChangedCommand = new CommandBase(OnTabChanged);
-
OnTabChanged("MonitoringTechnology.Views.FirstPageView");
+
+ ///初始化底部系统状态信息
+ if (SystemOperationView.isConnection)
+ {
+ this._isConnection = "已连接";
+ this.brush = new SolidColorBrush(Color.FromRgb(0, 255, 127));
+ }
+ else
+ {
+ this._isConnection = "未连接";
+ this.brush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
+ this._lYDevice = "";
+ }
}
private void OnTabChanged(object obj)
diff --git a/MonitoringTechnology/Views/SystemOperationView.xaml b/MonitoringTechnology/Views/SystemOperationView.xaml
index 12632f3..e66a81d 100644
--- a/MonitoringTechnology/Views/SystemOperationView.xaml
+++ b/MonitoringTechnology/Views/SystemOperationView.xaml
@@ -64,11 +64,11 @@
-
+
-
+
diff --git a/MonitoringTechnology/Views/SystemOperationView.xaml.cs b/MonitoringTechnology/Views/SystemOperationView.xaml.cs
index dc14dad..b7756f0 100644
--- a/MonitoringTechnology/Views/SystemOperationView.xaml.cs
+++ b/MonitoringTechnology/Views/SystemOperationView.xaml.cs
@@ -182,14 +182,15 @@ namespace MonitoringTechnology.Views
if (connected)
{
systemOperationViewModel.connectDevice = "断开连接";
- buttonConnect.Background = new SolidColorBrush(Color.FromRgb(199, 0, 6));
- buttonConnect.Foreground = new SolidColorBrush(Colors.White);
+ MainWindow.mainViewModel.IsConnection = "已连接";
+ MainWindow.mainViewModel.Brush = new SolidColorBrush(Color.FromRgb(0, 255, 127));//设置连接状态颜色-绿色
+ MainWindow.mainViewModel.LYDevice = LYScanPage._bleDevice.Name;
}
else
{
systemOperationViewModel.connectDevice = "连接设备";
- buttonConnect.Background = new SolidColorBrush(Colors.LightGray);
- buttonConnect.Foreground = new SolidColorBrush(Colors.Black);
+ MainWindow.mainViewModel.IsConnection = "未连接";
+ MainWindow.mainViewModel.Brush = new SolidColorBrush(Color.FromRgb(255, 0, 0));//设置连接状态颜色-红色
}
});
}
@@ -429,8 +430,9 @@ namespace MonitoringTechnology.Views
if (device.IsConnected == true)
{
systemOperationViewModel.connectDevice = "断开连接";
- buttonConnect.Background = new SolidColorBrush(Color.FromRgb(199, 0, 6));
- buttonConnect.Foreground = new SolidColorBrush(Colors.White);
+ MainWindow.mainViewModel.IsConnection = "已连接";
+ MainWindow.mainViewModel.Brush = new SolidColorBrush(Color.FromRgb(0, 255, 127));//设置连接状态颜色-绿色
+ MainWindow.mainViewModel.LYDevice = device.Name;
if (isSending == true)//如果处于循环发送状态
{