添加项目文件。
This commit is contained in:
98
ToolDetailViewModel.cs
Normal file
98
ToolDetailViewModel.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DrillTools
|
||||
{
|
||||
/// <summary>
|
||||
/// 刀具详情窗口视图模型
|
||||
/// </summary>
|
||||
public class ToolDetailViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private ToolItem? _tool;
|
||||
|
||||
/// <summary>
|
||||
/// 刀具对象
|
||||
/// </summary>
|
||||
public ToolItem? Tool
|
||||
{
|
||||
get => _tool;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _tool, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(WindowTitle));
|
||||
OnPropertyChanged(nameof(HoleLocationsHeader));
|
||||
OnPropertyChanged(nameof(FormattedHoleLocations));
|
||||
OnPropertyChanged(nameof(IsMachineCodeTool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口标题
|
||||
/// </summary>
|
||||
public string WindowTitle => Tool != null ? $"刀具详情 - T{Tool.ToolNumber:D2}" : "刀具详情";
|
||||
|
||||
/// <summary>
|
||||
/// 孔位信息标题
|
||||
/// </summary>
|
||||
public string HoleLocationsHeader => Tool != null ? $"孔位信息 (共{Tool.HoleLocations?.Count ?? 0}个)" : "孔位信息";
|
||||
|
||||
/// <summary>
|
||||
/// 格式化后的孔位信息
|
||||
/// </summary>
|
||||
public string FormattedHoleLocations
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Tool?.HoleLocations == null || Tool.HoleLocations.Count == 0)
|
||||
{
|
||||
return "无孔位数据";
|
||||
}
|
||||
|
||||
return string.Join(Environment.NewLine, Tool.HoleLocations);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为机台码刀具
|
||||
/// </summary>
|
||||
public bool IsMachineCodeTool => Tool?.ToolType == ToolType.MachineCode;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public ToolDetailViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用指定的刀具初始化视图模型
|
||||
/// </summary>
|
||||
/// <param name="tool">刀具对象</param>
|
||||
public ToolDetailViewModel(ToolItem tool) : this()
|
||||
{
|
||||
Tool = tool;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(field, value))
|
||||
return false;
|
||||
|
||||
field = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user