51 lines
1.9 KiB
C#
51 lines
1.9 KiB
C#
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using XP.Hardware.PLC.Sentry.ViewModels;
|
||
|
||
namespace XP.Hardware.PLC.Sentry.Views
|
||
{
|
||
/// <summary>
|
||
/// 写入值控件模板选择器,根据信号数据类型选择不同的写入控件 | Write value template selector, selects different write controls based on signal data type
|
||
/// bool → ToggleButton, byte/short/int → RadNumericUpDown(整数), single/double → RadNumericUpDown(浮点), string → TextBox
|
||
/// </summary>
|
||
public class WriteValueTemplateSelector : DataTemplateSelector
|
||
{
|
||
/// <summary>
|
||
/// bool 类型写入模板 | Bool type write template
|
||
/// </summary>
|
||
public DataTemplate BoolTemplate { get; set; }
|
||
|
||
/// <summary>
|
||
/// 整数类型写入模板(byte, short, int)| Integer type write template
|
||
/// </summary>
|
||
public DataTemplate IntegerTemplate { get; set; }
|
||
|
||
/// <summary>
|
||
/// 浮点类型写入模板(single, double)| Float type write template
|
||
/// </summary>
|
||
public DataTemplate FloatTemplate { get; set; }
|
||
|
||
/// <summary>
|
||
/// 字符串类型写入模板 | String type write template
|
||
/// </summary>
|
||
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);
|
||
}
|
||
}
|
||
}
|