NavisworksTransport/src/UI/WPF/Converters/BoolToBrushConverter.cs

38 lines
1.2 KiB
C#
Raw 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.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;
}
}
}