using System; using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; namespace TeamAAS.Converters { public class BoolToArrowConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is bool collapsed && collapsed) return "▶"; return "◀"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class BoolToWidthConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is bool collapsed && collapsed) return new GridLength(48); return new GridLength(280); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class InvertBoolToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is bool boolValue && boolValue) return Visibility.Collapsed; return Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } /// /// 运行状态圆点颜色:true(运行中)=绿色,false=灰色。 /// public class RunDotConverter : IValueConverter { private static readonly Brush Running = new SolidColorBrush( (Color)ColorConverter.ConvertFromString("#4CAF50")); private static readonly Brush Stopped = new SolidColorBrush( (Color)ColorConverter.ConvertFromString("#888888")); public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (value is bool b && b) ? Running : Stopped; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }