20211124_ZNZT_upperpc/MonitoringTechnology/ViewModels/MainViewModel.cs
2023-03-17 15:06:36 +08:00

156 lines
4.4 KiB
C#

using MonitoringTechnology.Base;
using MonitoringTechnology.Common;
using MonitoringTechnology.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
namespace MonitoringTechnology.ViewModels
{
public class MainViewModel : NotifyPropertyBase
{
/// <summary>
/// 当前蓝牙设备是否已连接
/// </summary>
private string _isConnection;
public string IsConnection
{
get { return _isConnection; }
set { _isConnection = value; this.RaisePropertyChanged(); }
}
/// <summary>
/// 连接标志 -绿色(已连接) / 红色(未连接)
/// </summary>
private SolidColorBrush brush;
public SolidColorBrush Brush
{
get { return brush; }
set { brush = value;this.RaisePropertyChanged(); }
}
/// <summary>
/// 蓝牙名称
/// </summary>
private string _lYDevice;
public string LYDevice
{
get { return _lYDevice; }
set { _lYDevice = value; this.RaisePropertyChanged(); }
}
/// <summary>
/// 电池电压
/// </summary>
private float _batteryVoltage;
public float F_BatteryVoltage
{
get { return _batteryVoltage; }
set { _batteryVoltage = value; this.RaisePropertyChanged(); }
}
/// <summary>
/// 充电电流
/// </summary>
public float _ChargingCurrent;
public float F_ChargingCurrent
{
get { return _ChargingCurrent; }
set { _ChargingCurrent = value; this.RaisePropertyChanged(); }
}
/// <summary>
/// 充电状态
/// </summary>
public string _State;
public string F_State
{
get { return _State; }
set { _State = value; this.RaisePropertyChanged(); }
}
private UIElement _mainContent;
public UIElement MainContent
{
get { return _mainContent; }
set
{
Set<UIElement>(ref _mainContent, value);
}
}
public CommandBase TabChangedCommand { get; set; }
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 = "";
this._batteryVoltage = 0;
this._ChargingCurrent = 0;
this._State = "未充电";
}
}
private void OnTabChanged(object obj)
{
if (obj == null) return;
// 完整方式
//string[] strValues = o.ToString().Split('|');
//Assembly assembly = Assembly.LoadFrom(strValues[0]);
//Type type = assembly.GetType(strValues[1]);
//this.MainContent = (UIElement)Activator.CreateInstance(type);
//切换页面之前清理一下内存
tools.ClearMemory(this);
// 简化方式,必须在同一个程序集下
if (obj.ToString().Equals("MonitoringTechnology.Views.SystemOperationView"))
{
if (LYScanPage._bleDevice.Mac != null)
{
SystemOperationView view = new SystemOperationView(LYScanPage._bleDevice);
MainWindow.mainViewModel.MainContent = view;
}
else
{
Type type = Type.GetType(obj.ToString());
this.MainContent = (UIElement)Activator.CreateInstance(type);
}
}
else
{
Type type = Type.GetType(obj.ToString());
this.MainContent = (UIElement)Activator.CreateInstance(type);
}
}
}
}