initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Avalonia.PropertyGrid.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Converts an Avalonia.Media.Color to a SolidColorBrush
|
||||
/// </summary>
|
||||
public class ColorToBrushConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Color color)
|
||||
{
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
|
||||
// Return transparent brush if not a color
|
||||
return new SolidColorBrush(Colors.Transparent);
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush && brush.Color != null)
|
||||
{
|
||||
return brush.Color;
|
||||
}
|
||||
|
||||
return Colors.Transparent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user