This commit is contained in:
121
ViewModels/MainViewModel.cs
Normal file
121
ViewModels/MainViewModel.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using MembranePoreTester.ViewModels;
|
||||
using System;
|
||||
using System.Windows.Media;
|
||||
using MembranePoreTester.Models;
|
||||
using MembranePoreTester.Services;
|
||||
|
||||
namespace MembranePoreTester.ViewModels
|
||||
{
|
||||
public partial class MainViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IHardwareService _hardwareService;
|
||||
|
||||
// 设备数据模型(界面绑定用)
|
||||
[ObservableProperty]
|
||||
private DeviceDataModel _deviceData = new DeviceDataModel();
|
||||
|
||||
// 通信状态
|
||||
[ObservableProperty]
|
||||
private string _communicationStatus = "未连接";
|
||||
|
||||
// 状态颜色
|
||||
[ObservableProperty]
|
||||
private SolidColorBrush _statusColor = new SolidColorBrush(Colors.Red);
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
// 注入硬件服务(实际项目中可用依赖注入)
|
||||
_hardwareService = new HardwareService();
|
||||
}
|
||||
|
||||
// 保存参数到硬件
|
||||
[RelayCommand]
|
||||
private void SaveParameters()
|
||||
{
|
||||
// 用户实现:调用硬件服务将 DeviceData 中的参数写入设备
|
||||
// _hardwareService.SaveDeviceData(DeviceData);
|
||||
CommunicationStatus = "参数已保存";
|
||||
StatusColor = new SolidColorBrush(Colors.Green);
|
||||
}
|
||||
|
||||
// 从硬件读取参数
|
||||
[RelayCommand]
|
||||
private void LoadParameters()
|
||||
{
|
||||
// 用户实现:从硬件读取数据并更新 DeviceData
|
||||
// var data = _hardwareService.LoadDeviceData();
|
||||
// DeviceData = data;
|
||||
CommunicationStatus = "参数已读取";
|
||||
StatusColor = new SolidColorBrush(Colors.Green);
|
||||
}
|
||||
|
||||
// 复位
|
||||
[RelayCommand]
|
||||
private void Reset()
|
||||
{
|
||||
// 用户实现:调用硬件复位
|
||||
// _hardwareService.Reset();
|
||||
CommunicationStatus = "复位指令已发送";
|
||||
}
|
||||
|
||||
// 左眼开
|
||||
[RelayCommand]
|
||||
private void OpenLeftEye()
|
||||
{
|
||||
// _hardwareService.OpenLeftEye();
|
||||
CommunicationStatus = "左眼开启指令已发送";
|
||||
}
|
||||
|
||||
// 右眼开
|
||||
[RelayCommand]
|
||||
private void OpenRightEye()
|
||||
{
|
||||
// _hardwareService.OpenRightEye();
|
||||
CommunicationStatus = "右眼开启指令已发送";
|
||||
}
|
||||
|
||||
// 反转
|
||||
[RelayCommand]
|
||||
private void Reverse()
|
||||
{
|
||||
// _hardwareService.ReverseMotor();
|
||||
CommunicationStatus = "反转指令已发送";
|
||||
}
|
||||
|
||||
// 正转
|
||||
[RelayCommand]
|
||||
private void Forward()
|
||||
{
|
||||
// _hardwareService.ForwardMotor();
|
||||
CommunicationStatus = "正转指令已发送";
|
||||
}
|
||||
|
||||
// 导航命令(供用户自行实现页面跳转)
|
||||
[RelayCommand]
|
||||
private void NavigateHome()
|
||||
{
|
||||
// 用户实现:切换到主页视图
|
||||
CommunicationStatus = "导航至主页";
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateTest()
|
||||
{
|
||||
CommunicationStatus = "导航至测试界面";
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateDataRecord()
|
||||
{
|
||||
CommunicationStatus = "导航至数据记录";
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateRecordScreen()
|
||||
{
|
||||
CommunicationStatus = "导航至记录画面";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
using MembranePoreTester.Communication;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MembranePoreTester.Communication;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MembranePoreTester.ViewModels
|
||||
{
|
||||
public class ViewModelBase : INotifyPropertyChanged
|
||||
public class ViewModelBase : ObservableObject
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user