Files
CSI-Z420-Tablet-Multi-Funct…/Helpers/ValueConverters.cs

82 lines
2.9 KiB
C#
Raw Normal View History

2026-05-05 15:31:24 +08:00
using System;
using System.Globalization;
using System.Windows.Data;
namespace TabletTester2025.Helpers
{
public class BasketOffsetConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isUp = (bool)value;
double maxOffset = System.Convert.ToDouble(parameter);
return isUp ? 0 : maxOffset;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
public class PassToTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isPass = (bool)value;
return isPass ? "合格" : "不合格";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
public class BoolToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool flag = (bool)value;
2026-05-06 16:41:32 +08:00
return flag ? "Green" : "Red";
2026-05-05 15:31:24 +08:00
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
public class StatusColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string status = value as string;
2026-05-16 17:47:46 +08:00
return status switch
{
"已连接" => "Green",
"连接中" => "Orange",
_ => "Red"
};
2026-05-05 15:31:24 +08:00
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
2026-05-06 16:41:32 +08:00
public class BoolToTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isClockwise = (bool)value;
return isClockwise ? "顺时针" : "逆时针";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
// 用于将 bool 方向转换为 "顺时针"/"逆时针"
public class BoolToDirectionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isClockwise = (bool)value;
return isClockwise ? "顺时针" : "逆时针";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
2026-05-16 17:47:46 +08:00
}