2025-04-24 20:56:44 +08:00
|
|
|
|
using System.Globalization;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
using Color = System.Windows.Media.Color;
|
|
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.Converters;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Autodesk颜色转Windows系统颜色
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Rv2WinColorConverter : IValueConverter
|
|
|
|
|
|
{
|
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
var color = (Autodesk.Revit.DB.Color)value;
|
|
|
|
|
|
//if (Autodesk.Revit.DB.SelectedColor.InvalidColorValue)
|
|
|
|
|
|
//{
|
|
|
|
|
|
//}
|
|
|
|
|
|
if (color is { IsValid: true })
|
|
|
|
|
|
{
|
|
|
|
|
|
var rgb = Color.FromRgb(color.Red, color.Green, color.Blue);
|
|
|
|
|
|
return rgb;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new Color();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
return value is Color rgb ? new Autodesk.Revit.DB.Color(rgb.R, rgb.G, rgb.B) : (object)Autodesk.Revit.DB.Color.InvalidColorValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|