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)//如果处于循环发送状态 {