AHAQ_QGNH/AnQing/Commons/IndexToSerialNumberConverter.cs
2025-05-19 09:31:47 +08:00

97 lines
3.2 KiB
C#
Raw Permalink 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;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
namespace AnQing.Commons
{
public class IndexConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ListViewItem item = (ListViewItem)value;
ListView listView = ItemsControl.ItemsControlFromItemContainer(item) as ListView;
int index = listView.ItemContainerGenerator.IndexFromContainer(item) + 1;
return index.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class EllipseFillConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool isOK)
{
return isOK ? Brushes.Green : Brushes.Red;
}
return Brushes.Gray; // 默认颜色
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class RunTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool isOK)
{
return isOK ? "连接成功" : "连接失败";
}
return "未知状态"; // 默认文本
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class ReadRunTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool isOK)
{
return isOK ? "采集中" : "空闲";
}
return "未知状态"; // 默认文本
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class StringToDateTimeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// 如果 StartTime 是空字符串,转换为 null
if (value is string str && string.IsNullOrEmpty(str))
{
return null; // 返回 null清空 DateTimePicker
}
return value; // 否则,返回原始值
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// 将 DateTime? 转换回字符串(如果为 null 则为空字符串)
return value == null ? "" : value.ToString();
}
}
}