118 lines
3.4 KiB
C#
118 lines
3.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(); }
|
|
}
|
|
|
|
|
|
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 = "";
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|