添加项目文件。
This commit is contained in:
26
SettingModule/SettingModule.cs
Normal file
26
SettingModule/SettingModule.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using SettingModule.Views;
|
||||
using SettingModule.Views.Dialogs;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SettingModule
|
||||
{
|
||||
[Module(OnDemand = true)]
|
||||
public class SettingModule : IModule
|
||||
{
|
||||
public void OnInitialized(IContainerProvider containerProvider)
|
||||
{
|
||||
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
|
||||
regionManager.RegisterViewWithRegion("ShellViewManager", typeof(SettingView));
|
||||
}
|
||||
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.RegisterForNavigation<SettingView>("SettingView");
|
||||
|
||||
// 设备连接配置弹窗
|
||||
containerRegistry.RegisterDialog<TCPConfigView>("TCPConfig");
|
||||
containerRegistry.RegisterDialog<SerialPortConfigView>("SerialPortConfig");
|
||||
containerRegistry.RegisterDialog<CANConfigView>("CANConfig");
|
||||
}
|
||||
}
|
||||
}
|
||||
14
SettingModule/SettingModule.csproj
Normal file
14
SettingModule/SettingModule.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UIShare\UIShare.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
134
SettingModule/ViewModels/Dialogs/CANConfigViewModel.cs
Normal file
134
SettingModule/ViewModels/Dialogs/CANConfigViewModel.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace SettingModule.ViewModels.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// CAN 连接配置对话框 VM。
|
||||
/// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。
|
||||
/// 参数对应 ZLGCANFD 构造函数 + 初始化并启动通道 方法。
|
||||
/// </summary>
|
||||
public class CANConfigViewModel : DialogViewModelBase
|
||||
{
|
||||
#region 属性
|
||||
|
||||
private string _title = "CAN 连接配置";
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
/// <summary>编辑用的副本,取消时不会污染宿主对象。</summary>
|
||||
private CANConfigVM _config = new();
|
||||
public CANConfigVM Config
|
||||
{
|
||||
get => _config;
|
||||
set => SetProperty(ref _config, value);
|
||||
}
|
||||
|
||||
/// <summary>常用仲裁域波特率。</summary>
|
||||
public ObservableCollection<string> CommonABitBauds { get; } = new()
|
||||
{
|
||||
"250000", "500000", "1000000"
|
||||
};
|
||||
|
||||
/// <summary>常用数据域波特率。</summary>
|
||||
public ObservableCollection<string> CommonDBitBauds { get; } = new()
|
||||
{
|
||||
"1000000", "2000000", "4000000", "5000000", "8000000"
|
||||
};
|
||||
|
||||
private string _errorMessage = string.Empty;
|
||||
public string ErrorMessage
|
||||
{
|
||||
get => _errorMessage;
|
||||
set => SetProperty(ref _errorMessage, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand CancelCommand { get; }
|
||||
#endregion
|
||||
|
||||
// 用于保存时把副本回写到原对象
|
||||
private DeviceInfoVM? _hostDevice;
|
||||
|
||||
public CANConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
SaveCommand = new DelegateCommand(OnSave);
|
||||
CancelCommand = new DelegateCommand(OnCancel);
|
||||
}
|
||||
|
||||
private bool Validate(out string error)
|
||||
{
|
||||
error = string.Empty;
|
||||
if (Config.DeviceType == 0)
|
||||
{
|
||||
error = "设备类型号不能为 0";
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(Config.ABitBaud))
|
||||
{
|
||||
error = "仲裁域波特率不能为空";
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(Config.DBitBaud))
|
||||
{
|
||||
error = "数据域波特率不能为空";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnSave()
|
||||
{
|
||||
if (!Validate(out var error))
|
||||
{
|
||||
ErrorMessage = error;
|
||||
return;
|
||||
}
|
||||
ErrorMessage = string.Empty;
|
||||
|
||||
// 把副本写回宿主
|
||||
if (_hostDevice != null)
|
||||
{
|
||||
_hostDevice.CANConfig ??= new CANConfigVM();
|
||||
Config.CopyTo(_hostDevice.CANConfig);
|
||||
_hostDevice.ConnectionType = "CAN";
|
||||
}
|
||||
|
||||
RequestClose.Invoke(ButtonResult.OK);
|
||||
}
|
||||
|
||||
private void OnCancel() => RequestClose.Invoke(ButtonResult.Cancel);
|
||||
|
||||
#region Prism Dialog 规范
|
||||
public override void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
_eventAggregator.GetEvent<OverlayEvent>().Publish(true);
|
||||
|
||||
if (parameters.ContainsKey("Device"))
|
||||
{
|
||||
_hostDevice = parameters.GetValue<DeviceInfoVM>("Device");
|
||||
Title = $"CAN 连接配置 - {_hostDevice?.DeviceName}";
|
||||
Config = new CANConfigVM(_hostDevice?.CANConfig);
|
||||
}
|
||||
else if (parameters.ContainsKey("Config"))
|
||||
{
|
||||
Config = new CANConfigVM(parameters.GetValue<CANConfigVM>("Config"));
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDialogClosed()
|
||||
{
|
||||
_eventAggregator.GetEvent<OverlayEvent>().Publish(false);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
164
SettingModule/ViewModels/Dialogs/SerialPortConfigViewModel.cs
Normal file
164
SettingModule/ViewModels/Dialogs/SerialPortConfigViewModel.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace SettingModule.ViewModels.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// 串口连接配置对话框 VM。
|
||||
/// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。
|
||||
/// </summary>
|
||||
public class SerialPortConfigViewModel : DialogViewModelBase
|
||||
{
|
||||
#region 属性
|
||||
|
||||
private string _title = "串口连接配置";
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
private SerialPortConfigVM _config = new();
|
||||
public SerialPortConfigVM Config
|
||||
{
|
||||
get => _config;
|
||||
set => SetProperty(ref _config, value);
|
||||
}
|
||||
|
||||
/// <summary>当前可用串口列表(OnDialogOpened 刷新)。</summary>
|
||||
public ObservableCollection<string> AvailablePorts { get; } = new();
|
||||
|
||||
public ObservableCollection<int> CommonBaudRates { get; } = new()
|
||||
{
|
||||
1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600
|
||||
};
|
||||
|
||||
public ObservableCollection<int> DataBitsList { get; } = new() { 5, 6, 7, 8 };
|
||||
|
||||
public ObservableCollection<string> StopBitsList { get; } = new()
|
||||
{
|
||||
"One", "OnePointFive", "Two"
|
||||
};
|
||||
|
||||
public ObservableCollection<string> ParityList { get; } = new()
|
||||
{
|
||||
"None", "Odd", "Even", "Mark", "Space"
|
||||
};
|
||||
|
||||
public ObservableCollection<int> CommonTimeouts { get; } = new()
|
||||
{
|
||||
500, 1000, 2000, 3000, 5000, 10000
|
||||
};
|
||||
|
||||
private string _errorMessage = string.Empty;
|
||||
public string ErrorMessage
|
||||
{
|
||||
get => _errorMessage;
|
||||
set => SetProperty(ref _errorMessage, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand CancelCommand { get; }
|
||||
public ICommand RefreshPortsCommand { get; }
|
||||
#endregion
|
||||
|
||||
private DeviceInfoVM? _hostDevice;
|
||||
|
||||
public SerialPortConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
SaveCommand = new DelegateCommand(OnSave);
|
||||
CancelCommand = new DelegateCommand(OnCancel);
|
||||
RefreshPortsCommand = new DelegateCommand(RefreshPorts);
|
||||
}
|
||||
|
||||
private void RefreshPorts()
|
||||
{
|
||||
AvailablePorts.Clear();
|
||||
|
||||
|
||||
// 若当前选中的串口不在可用列表中,仍保留显示,便于离线编辑
|
||||
if (!string.IsNullOrEmpty(Config.PortName) && !AvailablePorts.Contains(Config.PortName))
|
||||
AvailablePorts.Insert(0, Config.PortName);
|
||||
}
|
||||
|
||||
private bool Validate(out string error)
|
||||
{
|
||||
error = string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(Config.PortName))
|
||||
{
|
||||
error = "串口名称不能为空";
|
||||
return false;
|
||||
}
|
||||
if (Config.BaudRate <= 0)
|
||||
{
|
||||
error = "波特率必须大于 0";
|
||||
return false;
|
||||
}
|
||||
if (Config.DataBits < 5 || Config.DataBits > 8)
|
||||
{
|
||||
error = "数据位必须在 5 - 8 之间";
|
||||
return false;
|
||||
}
|
||||
if (Config.ReadTimeout < 0 || Config.WriteTimeout < 0)
|
||||
{
|
||||
error = "超时时间不能为负数";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnSave()
|
||||
{
|
||||
if (!Validate(out var error))
|
||||
{
|
||||
ErrorMessage = error;
|
||||
return;
|
||||
}
|
||||
ErrorMessage = string.Empty;
|
||||
|
||||
if (_hostDevice != null)
|
||||
{
|
||||
_hostDevice.SerialPortConfig ??= new SerialPortConfigVM();
|
||||
Config.CopyTo(_hostDevice.SerialPortConfig);
|
||||
_hostDevice.ConnectionType = "Serial";
|
||||
}
|
||||
|
||||
RequestClose.Invoke(ButtonResult.OK);
|
||||
}
|
||||
|
||||
private void OnCancel() => RequestClose.Invoke(ButtonResult.Cancel);
|
||||
|
||||
#region Prism Dialog 规范
|
||||
public override void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
_eventAggregator.GetEvent<OverlayEvent>().Publish(true);
|
||||
|
||||
if (parameters.ContainsKey("Device"))
|
||||
{
|
||||
_hostDevice = parameters.GetValue<DeviceInfoVM>("Device");
|
||||
Title = $"串口连接配置 - {_hostDevice?.DeviceName}";
|
||||
Config = new SerialPortConfigVM(_hostDevice?.SerialPortConfig);
|
||||
}
|
||||
else if (parameters.ContainsKey("Config"))
|
||||
{
|
||||
Config = new SerialPortConfigVM(parameters.GetValue<SerialPortConfigVM>("Config"));
|
||||
}
|
||||
|
||||
RefreshPorts();
|
||||
}
|
||||
|
||||
public override void OnDialogClosed()
|
||||
{
|
||||
_eventAggregator.GetEvent<OverlayEvent>().Publish(false);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
139
SettingModule/ViewModels/Dialogs/TCPConfigViewModel.cs
Normal file
139
SettingModule/ViewModels/Dialogs/TCPConfigViewModel.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
|
||||
namespace SettingModule.ViewModels.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// Tcp 连接配置对话框 VM。
|
||||
/// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。
|
||||
/// </summary>
|
||||
public class TCPConfigViewModel : DialogViewModelBase
|
||||
{
|
||||
#region 属性
|
||||
|
||||
private string _title = "Tcp 连接配置";
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
/// <summary>编辑用的副本,取消时不会污染宿主对象。</summary>
|
||||
private TcpConfigVM _config = new();
|
||||
public TcpConfigVM Config
|
||||
{
|
||||
get => _config;
|
||||
set => SetProperty(ref _config, value);
|
||||
}
|
||||
|
||||
/// <summary>常用 Modbus / 自定义协议端口建议。</summary>
|
||||
public ObservableCollection<int> CommonPorts { get; } = new()
|
||||
{
|
||||
502, 102, 80, 8080, 5020, 4840
|
||||
};
|
||||
|
||||
/// <summary>常用超时(毫秒)。</summary>
|
||||
public ObservableCollection<int> CommonTimeouts { get; } = new()
|
||||
{
|
||||
500, 1000, 2000, 3000, 5000, 10000
|
||||
};
|
||||
|
||||
private string _errorMessage = string.Empty;
|
||||
public string ErrorMessage
|
||||
{
|
||||
get => _errorMessage;
|
||||
set => SetProperty(ref _errorMessage, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand CancelCommand { get; }
|
||||
#endregion
|
||||
|
||||
// 用于保存时把副本回写到原对象
|
||||
private DeviceInfoVM? _hostDevice;
|
||||
|
||||
public TCPConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
SaveCommand = new DelegateCommand(OnSave);
|
||||
CancelCommand = new DelegateCommand(OnCancel);
|
||||
}
|
||||
|
||||
private bool Validate(out string error)
|
||||
{
|
||||
error = string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(Config.IPAddress))
|
||||
{
|
||||
error = "IP 地址不能为空";
|
||||
return false;
|
||||
}
|
||||
if (!System.Net.IPAddress.TryParse(Config.IPAddress, out _))
|
||||
{
|
||||
error = "IP 地址格式不正确";
|
||||
return false;
|
||||
}
|
||||
if (Config.Port <= 0 || Config.Port > 65535)
|
||||
{
|
||||
error = "端口范围应在 1 - 65535";
|
||||
return false;
|
||||
}
|
||||
if (Config.SendTimeout < 0 || Config.ReceiveTimeout < 0)
|
||||
{
|
||||
error = "超时时间不能为负数";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnSave()
|
||||
{
|
||||
if (!Validate(out var error))
|
||||
{
|
||||
ErrorMessage = error;
|
||||
return;
|
||||
}
|
||||
ErrorMessage = string.Empty;
|
||||
|
||||
// 把副本写回宿主
|
||||
if (_hostDevice != null)
|
||||
{
|
||||
_hostDevice.TcpConfig ??= new TcpConfigVM();
|
||||
Config.CopyTo(_hostDevice.TcpConfig);
|
||||
_hostDevice.ConnectionType = "Tcp";
|
||||
}
|
||||
|
||||
RequestClose.Invoke(ButtonResult.OK);
|
||||
}
|
||||
|
||||
private void OnCancel() => RequestClose.Invoke(ButtonResult.Cancel);
|
||||
|
||||
#region Prism Dialog 规范
|
||||
public override void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
_eventAggregator.GetEvent<OverlayEvent>().Publish(true);
|
||||
|
||||
if (parameters.ContainsKey("Device"))
|
||||
{
|
||||
_hostDevice = parameters.GetValue<DeviceInfoVM>("Device");
|
||||
Title = $"Tcp 连接配置 - {_hostDevice?.DeviceName}";
|
||||
Config = new TcpConfigVM(_hostDevice?.TcpConfig);
|
||||
}
|
||||
else if (parameters.ContainsKey("Config"))
|
||||
{
|
||||
Config = new TcpConfigVM(parameters.GetValue<TcpConfigVM>("Config"));
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDialogClosed()
|
||||
{
|
||||
_eventAggregator.GetEvent<OverlayEvent>().Publish(false);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
229
SettingModule/ViewModels/SettingViewModel.cs
Normal file
229
SettingModule/ViewModels/SettingViewModel.cs
Normal file
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using Prism.Commands;
|
||||
using Prism.Ioc;
|
||||
using UIShare.GlobalVariable;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace SettingModule.ViewModels
|
||||
{
|
||||
public class SettingViewModel : NavigateViewModelBase, IRegionMemberLifetime, IDisposable
|
||||
{
|
||||
|
||||
#region 属性
|
||||
private SystemConfig _systemConfig;
|
||||
public SystemConfig SystemConfig
|
||||
{
|
||||
get => _systemConfig;
|
||||
set => SetProperty(ref _systemConfig, value);
|
||||
}
|
||||
public bool KeepAlive => true;
|
||||
public string TestStatus
|
||||
{
|
||||
get => _testStatus;
|
||||
set => SetProperty(ref _testStatus, value);
|
||||
}
|
||||
|
||||
public DeviceInfoVM? SelectedDevice
|
||||
{
|
||||
get => _selectedDevice;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _selectedDevice, value))
|
||||
{
|
||||
OnSelectedDeviceChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<DeviceInfoVM> DeviceList
|
||||
{
|
||||
get => _deviceList;
|
||||
set => SetProperty(ref _deviceList, value);
|
||||
}
|
||||
public ObservableCollection<SharedParameter> SharedParameterList
|
||||
{
|
||||
get => _sharedParameterList;
|
||||
set => SetProperty(ref _sharedParameterList, value);
|
||||
}
|
||||
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set => SetProperty(ref _statusMessage, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<string> ConnectionTypes { get; } = new()
|
||||
{
|
||||
"None", "Tcp", "Serial", "CAN"
|
||||
};
|
||||
#endregion
|
||||
#region 命令
|
||||
public ICommand RefreshCommand { get; }
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand OpenConnectionConfigCommand { get; }
|
||||
#endregion
|
||||
#region 私有字段
|
||||
private IScopedProvider _scope;
|
||||
|
||||
private ScopedContext _scopedContext { get; set; }
|
||||
private GlobalInfo _globalInfo { get; }
|
||||
private bool IsInitiated = false;
|
||||
private string _testStatus = string.Empty;
|
||||
private DeviceInfoVM? _selectedDevice;
|
||||
private ObservableCollection<DeviceInfoVM> _deviceList;
|
||||
private ObservableCollection<SharedParameter> _sharedParameterList;
|
||||
private string _statusMessage = "请在左侧选择设备查看 / 编辑配置";
|
||||
#endregion
|
||||
public SettingViewModel(IContainerExtension container) : base(container)
|
||||
{
|
||||
_globalInfo = container.Resolve<GlobalInfo>();
|
||||
RefreshCommand = new DelegateCommand(OnExpand);
|
||||
SaveCommand = new DelegateCommand(OnSave);
|
||||
OpenConnectionConfigCommand = new DelegateCommand(OnOpenConnectionConfig);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DeviceList != null)
|
||||
{
|
||||
DeviceList = null!;
|
||||
}
|
||||
SelectedDevice = null;
|
||||
_scopedContext = null!;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LoggerHelper.ErrorWithNotify(TestStatus,$"释放配置管理组件(SettingViewModel)资源失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
#region 命令
|
||||
/// <summary>
|
||||
/// 选中设备切换:右侧配置面板靠 SelectedDevice 绑定自动刷新,
|
||||
/// 这里只负责更新状态栏提示。
|
||||
/// </summary>
|
||||
private void OnSelectedDeviceChanged()
|
||||
{
|
||||
if (SelectedDevice == null)
|
||||
{
|
||||
StatusMessage = "未选中设备";
|
||||
return;
|
||||
}
|
||||
StatusMessage = $"当前配置:{SelectedDevice.DeviceName}({SelectedDevice.DeviceType})";
|
||||
}
|
||||
|
||||
/// <summary>双击展开 / 折叠九宫格。</summary>
|
||||
private void OnExpand()
|
||||
{
|
||||
if (string.IsNullOrEmpty(TestStatus)) return;
|
||||
_globalInfo.CurrentScope = TestStatus;
|
||||
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus);
|
||||
}
|
||||
|
||||
/// <summary>保存当前 SystemConfig 到 SystemPath 下,文件名为 {Title}.json。</summary>
|
||||
private void OnSave()
|
||||
{
|
||||
if (SystemConfig == null)
|
||||
{
|
||||
StatusMessage = "无可保存的配置";
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(SystemConfig.Title))
|
||||
{
|
||||
StatusMessage = "保存失败:标题(Title)不能为空";
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigService.Save(SystemConfig);
|
||||
StatusMessage = $"已保存配置 [{SystemConfig.Title}.json] 至 {SystemConfig.SystemPath}({DateTime.Now:HH:mm:ss})";
|
||||
}
|
||||
|
||||
/// <summary>重置当前选中设备的配置(占位)。</summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开"连接配置"对话框。按 SelectedDevice.ConnectionType 决定开 Tcp 还是串口对话框。
|
||||
/// </summary>
|
||||
private void OnOpenConnectionConfig()
|
||||
{
|
||||
if (SelectedDevice == null)
|
||||
{
|
||||
StatusMessage = "请先在左侧选择设备";
|
||||
return;
|
||||
}
|
||||
|
||||
var dialogName = SelectedDevice.ConnectionType switch
|
||||
{
|
||||
"Tcp" => "TCPConfig",
|
||||
"Serial" => "SerialPortConfig",
|
||||
"CAN" => "CANConfig",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(dialogName))
|
||||
{
|
||||
StatusMessage = "当前设备未配置连接方式(请先选择 Tcp 或 Serial)";
|
||||
return;
|
||||
}
|
||||
|
||||
var p = new DialogParameters
|
||||
{
|
||||
{ "Device", SelectedDevice },
|
||||
{ "SystemConfig", SystemConfig }
|
||||
};
|
||||
|
||||
_dialogService.ShowDialog(dialogName, p, r =>
|
||||
{
|
||||
if (r.Result == ButtonResult.OK)
|
||||
{
|
||||
StatusMessage = $"已更新 [{SelectedDevice.DeviceName}] 的连接参数({DateTime.Now:HH:mm:ss})";
|
||||
}
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 重写
|
||||
public override void OnNavigatedTo(NavigationContext navigationContext)
|
||||
{
|
||||
base.OnNavigatedTo(navigationContext);
|
||||
if (!IsInitiated && navigationContext.Parameters.ContainsKey("Name"))
|
||||
{
|
||||
TestStatus = navigationContext.Parameters.GetValue<string>("Name");
|
||||
_scope = _globalInfo.ScopeDic[TestStatus];
|
||||
_scopedContext = _globalInfo.ContextDic[TestStatus];
|
||||
SystemConfig = _scope.Resolve<SystemConfig>();
|
||||
ConfigService.EnsureDefaultCanDevice(SystemConfig);
|
||||
if (DeviceList != null && DeviceList.Count > 0)
|
||||
{
|
||||
SelectedDevice = DeviceList[0];
|
||||
}
|
||||
DeviceList = SystemConfig.DeviceList;
|
||||
SharedParameterList=SystemConfig.SharedParameterList;
|
||||
if (SharedParameterList.Count == 0)
|
||||
{
|
||||
foreach (var device in SystemConfig.ParameterList)
|
||||
{
|
||||
var sharedParam = new SharedParameter
|
||||
{
|
||||
Id = device.ID.ToString(),
|
||||
ParameterName = device.Name,
|
||||
Value = device.Value is int intVal ? intVal : Convert.ToInt32(device.Value)
|
||||
};
|
||||
SharedParameterList.Add(sharedParam);
|
||||
}
|
||||
}
|
||||
IsInitiated = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
131
SettingModule/Views/Dialogs/CANConfigView.xaml
Normal file
131
SettingModule/Views/Dialogs/CANConfigView.xaml
Normal file
@@ -0,0 +1,131 @@
|
||||
<UserControl x:Class="SettingModule.Views.Dialogs.CANConfigView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SettingModule.Views.Dialogs"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
Background="White"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
Width="440"
|
||||
Height="360">
|
||||
<prism:Dialog.WindowStyle>
|
||||
<Style BasedOn="{StaticResource DialogUserManageStyle}"
|
||||
TargetType="Window" />
|
||||
</prism:Dialog.WindowStyle>
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:StringToVisibilityConverter x:Key="StringToVisibility"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<GroupBox Padding="12,8,12,8"
|
||||
helpers:WindowDragHelper.EnableWindowDrag="True">
|
||||
<GroupBox.Header>
|
||||
<Grid Margin="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Title}"
|
||||
Foreground="White"
|
||||
VerticalAlignment="Center"
|
||||
Margin="5,0,10,0" />
|
||||
</Grid>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 表单 -->
|
||||
<Grid Grid.Row="0" Margin="0,4,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 设备类型号 -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="设备类型号:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Margin="0,6"
|
||||
materialDesign:HintAssist.Hint="43 = USBCANFD-400U"
|
||||
Text="{Binding Config.DeviceType, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<!-- 设备索引 -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
Text="设备索引:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Margin="0,6"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding Config.DeviceIndex, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<!-- 仲裁域波特率 -->
|
||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||
Text="仲裁域波特率:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="2" Grid.Column="1" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonABitBauds}"
|
||||
Text="{Binding Config.ABitBaud, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<!-- 数据域波特率 -->
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
Text="数据域波特率:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="3" Grid.Column="1" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonDBitBauds}"
|
||||
Text="{Binding Config.DBitBaud, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<!-- 终端电阻 -->
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||
Text="终端电阻:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ToggleButton Grid.Row="4" Grid.Column="1" Margin="0,6"
|
||||
IsChecked="{Binding Config.EnableTerminalResistance}"
|
||||
Style="{StaticResource MaterialDesignSwitchToggleButton}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<TextBlock Grid.Row="1"
|
||||
Margin="0,8,0,0"
|
||||
Foreground="#D32F2F"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding ErrorMessage}"
|
||||
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisibility}}"/>
|
||||
|
||||
<!-- 按钮 -->
|
||||
<StackPanel Grid.Row="2"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,12,0,0">
|
||||
<Button Content="取消"
|
||||
Width="80" Padding="0,4"
|
||||
Command="{Binding CancelCommand}"/>
|
||||
<Button Content="保存"
|
||||
Width="80" Padding="0,4"
|
||||
Margin="10,0,0,0"
|
||||
IsDefault="True"
|
||||
Command="{Binding SaveCommand}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</UserControl>
|
||||
15
SettingModule/Views/Dialogs/CANConfigView.xaml.cs
Normal file
15
SettingModule/Views/Dialogs/CANConfigView.xaml.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SettingModule.Views.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// CANConfigView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class CANConfigView : UserControl
|
||||
{
|
||||
public CANConfigView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
153
SettingModule/Views/Dialogs/SerialPortConfigView.xaml
Normal file
153
SettingModule/Views/Dialogs/SerialPortConfigView.xaml
Normal file
@@ -0,0 +1,153 @@
|
||||
<UserControl x:Class="SettingModule.Views.Dialogs.SerialPortConfigView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SettingModule.Views.Dialogs"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
Background="White"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
Width="440"
|
||||
Height="430">
|
||||
<prism:Dialog.WindowStyle>
|
||||
<Style BasedOn="{StaticResource DialogUserManageStyle}"
|
||||
TargetType="Window" />
|
||||
</prism:Dialog.WindowStyle>
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:StringToVisibilityConverter x:Key="StringToVisibility"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<GroupBox Padding="12,8,12,8" materialDesign:HintAssist.Hint=""
|
||||
helpers:WindowDragHelper.EnableWindowDrag="True">
|
||||
<GroupBox.Header>
|
||||
<Grid Margin="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Title}"
|
||||
Foreground="White"
|
||||
VerticalAlignment="Center"
|
||||
Margin="5,0,10,0" />
|
||||
</Grid>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 表单 -->
|
||||
<Grid Grid.Row="0" Margin="0,4,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="串口名称:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="0" Grid.Column="1" Margin="0,6"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
IsEditable="True"
|
||||
ItemsSource="{Binding AvailablePorts}"
|
||||
Text="{Binding Config.PortName, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Grid.Row="0" Grid.Column="2" Margin="6,6,0,6"
|
||||
Padding="8,0" Content="刷新"
|
||||
Command="{Binding RefreshPortsCommand}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
Text="波特率:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonBaudRates}"
|
||||
Text="{Binding Config.BaudRate, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||
Text="数据位:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
|
||||
ItemsSource="{Binding DataBitsList}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
SelectedItem="{Binding Config.DataBits}"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
Text="停止位:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
|
||||
ItemsSource="{Binding StopBitsList}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
SelectedItem="{Binding Config.StopBits}"/>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||
Text="校验位:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
|
||||
ItemsSource="{Binding ParityList}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
SelectedItem="{Binding Config.Parity}"/>
|
||||
|
||||
<TextBlock Grid.Row="5" Grid.Column="0"
|
||||
Text="读取超时(ms):"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonTimeouts}"
|
||||
Text="{Binding Config.ReadTimeout, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="6" Grid.Column="0"
|
||||
Text="写入超时(ms):"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonTimeouts}"
|
||||
Text="{Binding Config.WriteTimeout, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<TextBlock Grid.Row="1"
|
||||
Margin="0,8,0,0"
|
||||
Foreground="#D32F2F"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding ErrorMessage}"
|
||||
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisibility}}"/>
|
||||
|
||||
<!-- 按钮 -->
|
||||
<StackPanel Grid.Row="2"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,12,0,0">
|
||||
<Button Content="取消"
|
||||
Width="80" Padding="0,4"
|
||||
Command="{Binding CancelCommand}"/>
|
||||
<Button Content="保存"
|
||||
Width="80" Padding="0,4"
|
||||
Margin="10,0,0,0"
|
||||
IsDefault="True"
|
||||
Command="{Binding SaveCommand}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</UserControl>
|
||||
28
SettingModule/Views/Dialogs/SerialPortConfigView.xaml.cs
Normal file
28
SettingModule/Views/Dialogs/SerialPortConfigView.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SettingModule.Views.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// SerialPortConfigView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SerialPortConfigView : UserControl
|
||||
{
|
||||
public SerialPortConfigView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
SettingModule/Views/Dialogs/TCPConfigView.xaml
Normal file
120
SettingModule/Views/Dialogs/TCPConfigView.xaml
Normal file
@@ -0,0 +1,120 @@
|
||||
<UserControl x:Class="SettingModule.Views.Dialogs.TCPConfigView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SettingModule.Views.Dialogs"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
Background="White"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
Width="420"
|
||||
Height="320">
|
||||
<prism:Dialog.WindowStyle>
|
||||
<Style BasedOn="{StaticResource DialogUserManageStyle}"
|
||||
TargetType="Window" />
|
||||
</prism:Dialog.WindowStyle>
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:StringToVisibilityConverter x:Key="StringToVisibility"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<GroupBox Padding="12,8,12,8"
|
||||
helpers:WindowDragHelper.EnableWindowDrag="True">
|
||||
<GroupBox.Header>
|
||||
<Grid Margin="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Title}"
|
||||
Foreground="White"
|
||||
VerticalAlignment="Center"
|
||||
Margin="5,0,10,0" />
|
||||
</Grid>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 表单 -->
|
||||
<Grid Grid.Row="0" Margin="0,4,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="IP 地址:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Margin="0,6"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding Config.IPAddress, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
Text="端口:"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonPorts}"
|
||||
Text="{Binding Config.Port, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||
Text="发送超时(ms):"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="2" Grid.Column="1" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonTimeouts}"
|
||||
Text="{Binding Config.SendTimeout, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
Text="接收超时(ms):"
|
||||
VerticalAlignment="Center" Margin="0,6"/>
|
||||
<ComboBox Grid.Row="3" Grid.Column="1" Margin="0,6"
|
||||
IsEditable="True"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
ItemsSource="{Binding CommonTimeouts}"
|
||||
Text="{Binding Config.ReceiveTimeout, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<TextBlock Grid.Row="1"
|
||||
Margin="0,8,0,0"
|
||||
Foreground="#D32F2F"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding ErrorMessage}"
|
||||
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisibility}}"/>
|
||||
|
||||
<!-- 按钮 -->
|
||||
<StackPanel Grid.Row="2"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,12,0,0">
|
||||
<Button Content="取消"
|
||||
Width="80" Padding="0,4"
|
||||
Command="{Binding CancelCommand}"/>
|
||||
<Button Content="保存"
|
||||
Width="80" Padding="0,4"
|
||||
Margin="10,0,0,0"
|
||||
IsDefault="True"
|
||||
Command="{Binding SaveCommand}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</UserControl>
|
||||
28
SettingModule/Views/Dialogs/TCPConfigView.xaml.cs
Normal file
28
SettingModule/Views/Dialogs/TCPConfigView.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SettingModule.Views.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// TCPConfigView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class TCPConfigView : UserControl
|
||||
{
|
||||
public TCPConfigView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
619
SettingModule/Views/SettingView.xaml
Normal file
619
SettingModule/Views/SettingView.xaml
Normal file
@@ -0,0 +1,619 @@
|
||||
<UserControl x:Class="SettingModule.Views.SettingView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:b="clr-namespace:UIShare.Behaviors;assembly=UIShare"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="700"
|
||||
d:DesignWidth="1200">
|
||||
<UserControl.Resources>
|
||||
<converters:LessThanConverter x:Key="LessThanConverter"/>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Border Background="#F5F7FA">
|
||||
<i:Interaction.Behaviors>
|
||||
<b:MouseDoubleClickBehavior
|
||||
Command="{Binding DataContext.RefreshCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
|
||||
</i:Interaction.Behaviors>
|
||||
|
||||
<Grid x:Name="RootGrid" Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition>
|
||||
<RowDefinition.Style>
|
||||
<Style TargetType="RowDefinition">
|
||||
<Setter Property="Height" Value="Auto"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Height" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</RowDefinition.Style>
|
||||
</RowDefinition>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition>
|
||||
<RowDefinition.Style>
|
||||
<Style TargetType="RowDefinition">
|
||||
<Setter Property="Height" Value="Auto"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Height" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</RowDefinition.Style>
|
||||
</RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- ========== Row0:标题 ========== -->
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="{Binding TestStatus, StringFormat=设置界面 - {0}}"
|
||||
FontSize="20" FontWeight="Bold"
|
||||
Margin="4,0,0,8">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
|
||||
<!-- ========== Row1:主体(TabControl 切换两个面板)========== -->
|
||||
<TabControl Grid.Row="1"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Padding="0">
|
||||
|
||||
<!-- ============== Tab 1:设备列表 ============== -->
|
||||
<TabItem Header="设备列表">
|
||||
<Grid Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition>
|
||||
<ColumnDefinition.Style>
|
||||
<Style TargetType="ColumnDefinition">
|
||||
<Setter Property="Width" Value="240"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Width" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ColumnDefinition.Style>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition>
|
||||
<ColumnDefinition.Style>
|
||||
<Style TargetType="ColumnDefinition">
|
||||
<Setter Property="Width" Value="6"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Width" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ColumnDefinition.Style>
|
||||
</ColumnDefinition>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Border Grid.Column="0"
|
||||
Background="White"
|
||||
BorderBrush="#DDD" BorderThickness="1"
|
||||
CornerRadius="4">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
<DockPanel>
|
||||
<Border DockPanel.Dock="Top"
|
||||
Background="#ECEFF4"
|
||||
Padding="8,4">
|
||||
<TextBlock Text="设备列表" FontWeight="Bold"/>
|
||||
</Border>
|
||||
<ListBox ItemsSource="{Binding DeviceList}"
|
||||
SelectedItem="{Binding SelectedDevice}"
|
||||
BorderThickness="0"
|
||||
HorizontalContentAlignment="Stretch">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Margin="4,6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0">
|
||||
<TextBlock Text="{Binding DeviceName}" FontWeight="Bold"/>
|
||||
<TextBlock Text="{Binding DeviceType}"
|
||||
Foreground="#888" FontSize="11"
|
||||
Margin="0,2,0,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Border Width="8" Height="8" CornerRadius="4"
|
||||
Margin="0,0,4,0" VerticalAlignment="Center">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#CCC"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsEnabled}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<GridSplitter Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="Transparent">
|
||||
<GridSplitter.Style>
|
||||
<Style TargetType="GridSplitter">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</GridSplitter.Style>
|
||||
</GridSplitter>
|
||||
|
||||
<Border Grid.Column="2"
|
||||
Background="White"
|
||||
BorderBrush="#DDD" BorderThickness="1"
|
||||
CornerRadius="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Grid.Row="0"
|
||||
Background="#ECEFF4"
|
||||
Padding="10,6"
|
||||
BorderBrush="#DDD" BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
FontWeight="Bold">
|
||||
<Run Text="配置:"/>
|
||||
<Run Text="{Binding SelectedDevice.DeviceName, FallbackValue=未选中}"/>
|
||||
</TextBlock>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
|
||||
<Button Content="保存" Command="{Binding SaveCommand}" Padding="12,4" Margin="6,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<ScrollViewer Grid.Row="1"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
Padding="14">
|
||||
<StackPanel>
|
||||
<Border Background="White"
|
||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||
CornerRadius="4" Padding="14"
|
||||
Margin="0,0,0,12">
|
||||
<StackPanel>
|
||||
<TextBlock Text="基本信息" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="设备名称:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SelectedDevice.DeviceName, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="设备类型:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="1" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SelectedDevice.DeviceType, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="备注说明:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="2" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SelectedDevice.Remark, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="启用状态:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<CheckBox materialDesign:HintAssist.Hint="" Grid.Row="3" Grid.Column="1" Margin="0,6"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{Binding SelectedDevice.IsEnabled}"
|
||||
Content="启用此设备"/>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" Text="连接状态:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<StackPanel Grid.Row="4" Grid.Column="1" Orientation="Horizontal" Margin="0,6">
|
||||
<Border Width="10" Height="10" CornerRadius="5"
|
||||
VerticalAlignment="Center" Margin="0,0,6,0">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#CCC"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedDevice.IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未连接"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedDevice.IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已连接"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border Background="White"
|
||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||
CornerRadius="4" Padding="14"
|
||||
Margin="0,0,0,12">
|
||||
<StackPanel>
|
||||
<TextBlock Text="连接参数" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="连接方式:"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,4"/>
|
||||
<ComboBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1"
|
||||
Margin="0,4"
|
||||
ItemsSource="{Binding ConnectionTypes}"
|
||||
SelectedItem="{Binding SelectedDevice.ConnectionType,Mode=TwoWay}"/>
|
||||
<Button Grid.Row="0" Grid.Column="2"
|
||||
Content="配置..."
|
||||
Margin="8,4,0,4" Padding="14,2"
|
||||
Command="{Binding OpenConnectionConfigCommand}"/>
|
||||
|
||||
<!-- Tcp 参数预览 -->
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Margin="0,4,0,0" Orientation="Horizontal">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedDevice.ConnectionType}" Value="Tcp">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<TextBlock Foreground="#666" FontSize="12">
|
||||
<Run Text="IP:"/>
|
||||
<Run Text="{Binding SelectedDevice.TcpConfig.IPAddress}"/>
|
||||
<Run Text=" 端口:"/>
|
||||
<Run Text="{Binding SelectedDevice.TcpConfig.Port}"/>
|
||||
<Run Text=" 发送/接收超时:"/>
|
||||
<Run Text="{Binding SelectedDevice.TcpConfig.SendTimeout}"/>
|
||||
<Run Text="/"/>
|
||||
<Run Text="{Binding SelectedDevice.TcpConfig.ReceiveTimeout}"/>
|
||||
<Run Text=" ms"/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 串口参数预览 -->
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Margin="0,4,0,0" Orientation="Horizontal">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedDevice.ConnectionType}" Value="Serial">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<TextBlock Foreground="#666" FontSize="12">
|
||||
<Run Text="串口:"/>
|
||||
<Run Text="{Binding SelectedDevice.SerialPortConfig.PortName}"/>
|
||||
<Run Text=" 波特率:"/>
|
||||
<Run Text="{Binding SelectedDevice.SerialPortConfig.BaudRate}"/>
|
||||
<Run Text=" 数据/停止/校验:"/>
|
||||
<Run Text="{Binding SelectedDevice.SerialPortConfig.DataBits}"/>
|
||||
<Run Text="/"/>
|
||||
<Run Text="{Binding SelectedDevice.SerialPortConfig.StopBits}"/>
|
||||
<Run Text="/"/>
|
||||
<Run Text="{Binding SelectedDevice.SerialPortConfig.Parity}"/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<!-- CAN 参数预览 -->
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
|
||||
Margin="0,4,0,0" Orientation="Horizontal">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedDevice.ConnectionType}" Value="CAN">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<TextBlock Foreground="#666" FontSize="12">
|
||||
<Run Text="设备类型:"/>
|
||||
<Run Text="{Binding SelectedDevice.CANConfig.DeviceType}"/>
|
||||
<Run Text=" 设备索引:"/>
|
||||
<Run Text="{Binding SelectedDevice.CANConfig.DeviceIndex}"/>
|
||||
<Run Text=" 仲裁/数据波特率:"/>
|
||||
<Run Text="{Binding SelectedDevice.CANConfig.ABitBaud}"/>
|
||||
<Run Text="/"/>
|
||||
<Run Text="{Binding SelectedDevice.CANConfig.DBitBaud}"/>
|
||||
<Run Text=" 终端电阻:"/>
|
||||
<Run Text="{Binding SelectedDevice.CANConfig.EnableTerminalResistance}"/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border Background="White"
|
||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||
CornerRadius="4" Padding="14">
|
||||
<!--<StackPanel>
|
||||
<TextBlock Text="高级设置" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||
<TextBlock Foreground="#888" FontSize="12" TextWrapping="Wrap"
|
||||
Text="超时、重试、缓存策略等高级选项后续在此扩展。"/>
|
||||
</StackPanel>-->
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
<!-- ============== Tab 2:系统参数(编辑 SystemConfig)============== -->
|
||||
<TabItem Header="系统参数">
|
||||
<Border Background="White"
|
||||
BorderBrush="#DDD" BorderThickness="1"
|
||||
CornerRadius="4"
|
||||
Margin="0,8,0,0">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Grid.Row="0"
|
||||
Background="#ECEFF4"
|
||||
Padding="10,6"
|
||||
BorderBrush="#DDD" BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="系统参数(SystemConfig)"
|
||||
VerticalAlignment="Center"
|
||||
FontWeight="Bold"/>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<Button Content="保存" Command="{Binding SaveCommand}" Padding="12,4" Margin="6,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<ScrollViewer Grid.Row="1"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
Padding="14">
|
||||
<StackPanel>
|
||||
<Border Background="White"
|
||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||
CornerRadius="4" Padding="14"
|
||||
Margin="0,0,0,12">
|
||||
<StackPanel>
|
||||
<TextBlock Text="基础设置" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="140"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="性能等级:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<Grid Grid.Row="2" Grid.Column="1" Margin="0,4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Slider Grid.Column="0"
|
||||
Minimum="100" Maximum="200"
|
||||
TickFrequency="10" IsSnapToTickEnabled="True"
|
||||
VerticalAlignment="Center"
|
||||
Value="{Binding SystemConfig.PerformanceLevel}"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding SystemConfig.PerformanceLevel}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="8,0,0,0"
|
||||
MinWidth="30"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border Background="White"
|
||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||
CornerRadius="4" Padding="14"
|
||||
Margin="0,0,0,12">
|
||||
<StackPanel>
|
||||
<TextBlock Text="公共变量(SharedParameterList)" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||
<TextBlock Foreground="#888" FontSize="12" TextWrapping="Wrap"
|
||||
Text="每个台架可独立设置自己的通道号等整型变量;新建或打开程序时会用此处值覆盖程序中的同名变量。" Margin="0,0,0,10"/>
|
||||
<ItemsControl ItemsSource="{Binding SharedParameterList}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Margin="0,4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="160"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="{Binding ParameterName}" VerticalAlignment="Center"/>
|
||||
<TextBox Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border Background="White"
|
||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||
CornerRadius="4" Padding="14"
|
||||
Margin="0,0,0,12">
|
||||
<StackPanel>
|
||||
<TextBlock Text="路径配置" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="140"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="DLL 路径:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SystemConfig.DLLFilePath, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="子程序路径:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="1" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SystemConfig.SubProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="默认程序文件:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="2" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SystemConfig.DefaultProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="默认 BLF 文件:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="3" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SystemConfig.DefaultBLFFilePath, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" Text="默认 DBC 文件:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBox materialDesign:HintAssist.Hint="" Grid.Row="4" Grid.Column="1" Margin="0,4"
|
||||
Text="{Binding SystemConfig.DefaultDBCFilePath, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border Background="#FAFAFA"
|
||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||
CornerRadius="4" Padding="14">
|
||||
<StackPanel>
|
||||
<TextBlock Text="只读信息" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="140"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="标题:" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0,4" Foreground="#555"
|
||||
Text="{Binding SystemConfig.Title}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="TSMaster 名称:" VerticalAlignment="Center" Margin="0,4"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0,4" Foreground="#555"
|
||||
Text="{Binding SystemConfig.TSMasterName}"/>
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="系统数据目录:" VerticalAlignment="Center"/>
|
||||
<TextBlock Grid.Column="1" Grid.Row="2"
|
||||
Text="{Binding SystemConfig.SystemPath}" Margin="0,4"
|
||||
Foreground="#555"
|
||||
TextWrapping="Wrap"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Border>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<!-- ========== Row2:状态栏 ========== -->
|
||||
<Border Grid.Row="2"
|
||||
Background="#ECEFF4"
|
||||
Padding="8,4" Margin="0,6,0,0"
|
||||
CornerRadius="2">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
<TextBlock Text="{Binding StatusMessage}"
|
||||
Foreground="#444"
|
||||
FontSize="12"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
28
SettingModule/Views/SettingView.xaml.cs
Normal file
28
SettingModule/Views/SettingView.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SettingModule.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// SettingView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SettingView : UserControl
|
||||
{
|
||||
public SettingView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user