Files
XplorePlane/XP.Hardware.PLC.Sentry/Views/WriteValueTemplateSelector.cs
T

51 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
}