38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System;
|
||
using System.Globalization;
|
||
using System.Windows;
|
||
using System.Windows.Data;
|
||
using System.Windows.Media;
|
||
|
||
namespace NavisworksTransport.UI.WPF.Converters
|
||
{
|
||
/// <summary>
|
||
/// 布尔值到画刷的转换器
|
||
/// true 返回绿色,false 返回灰色
|
||
/// </summary>
|
||
public class BoolToBrushConverter : IValueConverter
|
||
{
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||
{
|
||
if (value is bool boolValue && boolValue)
|
||
{
|
||
// 根据参数返回不同颜色,默认为绿色
|
||
string colorName = parameter as string ?? "Green";
|
||
switch (colorName.ToString())
|
||
{
|
||
case "Blue": return Brushes.DodgerBlue;
|
||
case "Red": return Brushes.Crimson;
|
||
case "Orange": return Brushes.DarkOrange;
|
||
default: return Brushes.ForestGreen;
|
||
}
|
||
}
|
||
return Brushes.Gray;
|
||
}
|
||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||
{
|
||
return Binding.DoNothing;
|
||
}
|
||
}
|
||
}
|