using System.Windows; using System.Windows.Controls; using XP.Hardware.PLC.Sentry.ViewModels; namespace XP.Hardware.PLC.Sentry.Views { /// /// 写入值控件模板选择器,根据信号数据类型选择不同的写入控件 | Write value template selector, selects different write controls based on signal data type /// bool → ToggleButton, byte/short/int → RadNumericUpDown(整数), single/double → RadNumericUpDown(浮点), string → TextBox /// public class WriteValueTemplateSelector : DataTemplateSelector { /// /// bool 类型写入模板 | Bool type write template /// public DataTemplate BoolTemplate { get; set; } /// /// 整数类型写入模板(byte, short, int)| Integer type write template /// public DataTemplate IntegerTemplate { get; set; } /// /// 浮点类型写入模板(single, double)| Float type write template /// public DataTemplate FloatTemplate { get; set; } /// /// 字符串类型写入模板 | String type write template /// public DataTemplate StringTemplate { get; set; } public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (item is SignalRowViewModel row) { return row.Type?.ToLowerInvariant() switch { "bool" => BoolTemplate, "byte" or "short" or "int" => IntegerTemplate, "single" or "double" => FloatTemplate, "string" => StringTemplate, _ => StringTemplate // 默认使用文本框 | Default to TextBox }; } return base.SelectTemplate(item, container); } } }