修改了设备列表的界面

This commit is contained in:
2025-09-14 20:46:31 +08:00
parent ebf67b98fa
commit d923b6a116
10 changed files with 469 additions and 149 deletions

View File

@@ -0,0 +1,51 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
namespace DMS.WPF.Converters
{
/// <summary>
/// 布尔值到颜色转换器。根据布尔值返回不同的颜色。
/// 参数格式: "TrueColor;FalseColor"
/// </summary>
public class BoolToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
string param = parameter as string;
if (!string.IsNullOrEmpty(param))
{
string[] colors = param.Split(';');
if (colors.Length == 2)
{
try
{
string colorString = boolValue ? colors[0] : colors[1];
Color color = (Color)ColorConverter.ConvertFromString(colorString);
return new SolidColorBrush(color);
}
catch (FormatException)
{
// 如果颜色格式无效,返回默认颜色
}
}
}
// 默认颜色
Color defaultColor = boolValue ? Colors.Green : Colors.Red;
return new SolidColorBrush(defaultColor);
}
// 如果值不是布尔值,返回红色
return new SolidColorBrush(Colors.Red);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace DMS.WPF.Converters
{
/// <summary>
/// 布尔值到字符串转换器。根据布尔值返回不同的字符串。
/// 参数格式: "TrueString;FalseString"
/// </summary>
public class BoolToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
string param = parameter as string;
if (!string.IsNullOrEmpty(param))
{
string[] strings = param.Split(';');
if (strings.Length == 2)
{
return boolValue ? strings[0] : strings[1];
}
}
// 默认返回
return boolValue ? "是" : "否";
}
return "未知";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace DMS.WPF.Converters
{
/// <summary>
/// 布尔值到可见性转换器。当绑定的布尔值为true时返回Visible否则返回Collapsed。
/// </summary>
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return boolValue ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Visibility visibility)
{
return visibility == Visibility.Visible;
}
return false;
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace DMS.WPF.Converters
{
/// <summary>
/// 计数到可见性转换器。当集合为空时返回Visible否则返回Collapsed。
/// </summary>
public class CountToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is ICollection collection)
{
return collection.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}