- Improved PropertyGrid.axaml formatting and control styles; ensured spinner buttons are always visible and ColorPicker layouts are flexible; disabled horizontal scrolling in property list. - Reformatted property editors and group/category display for clarity. - Made all value converters sealed, added XML docs, and updated ConvertBack to throw NotImplementedException where unsupported. - Enhanced search logic to use StringComparison.OrdinalIgnoreCase. - Minor code style fixes (e.g., char literals for string checks). - Removed default value assignment for _useProxy in AdvancedConfiguration.cs. - Updated Program.cs in examples to use sealed Program classes. - Added PropertyGrid.slnx to organize solution and projects.
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
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 sealed class ColorToBrushConverter : IValueConverter
|
|
{
|
|
/// <summary>
|
|
/// Converts a Color to a SolidColorBrush.
|
|
/// </summary>
|
|
/// <param name="value">The Color value to convert.</param>
|
|
/// <param name="targetType">The target type.</param>
|
|
/// <param name="parameter">Optional parameter.</param>
|
|
/// <param name="culture">Culture information.</param>
|
|
/// <returns>A SolidColorBrush with the specified color.</returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a SolidColorBrush back to a Color.
|
|
/// </summary>
|
|
/// <param name="value">The SolidColorBrush value to convert back.</param>
|
|
/// <param name="targetType">The target type.</param>
|
|
/// <param name="parameter">Optional parameter.</param>
|
|
/// <param name="culture">Culture information.</param>
|
|
/// <returns>The Color from the brush.</returns>
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is SolidColorBrush brush)
|
|
{
|
|
return brush.Color;
|
|
}
|
|
|
|
return Colors.Transparent;
|
|
}
|
|
}
|