Files
PropertyGrid/Avalonia.PropertyGrid/Converters/NegateBoolConverter.cs
T
Matthias Heil 37720f103b Refactor PropertyGrid UI, converters, and solution setup
- 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.
2026-08-13 09:49:27 +02:00

46 lines
1.5 KiB
C#

using System;
using System.Globalization;
using Avalonia.Data.Converters;
namespace Avalonia.PropertyGrid.Controls;
/// <summary>
/// Converts boolean value to its negation for two-way binding
/// </summary>
public sealed class NegateBoolConverter : IValueConverter
{
/// <summary>
/// Converts a boolean value to its negation.
/// </summary>
/// <param name="value">The boolean value to convert.</param>
/// <param name="targetType">The target type.</param>
/// <param name="parameter">Optional parameter.</param>
/// <param name="culture">Culture information.</param>
/// <returns>The negated boolean value.</returns>
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return false;
}
/// <summary>
/// Converts a boolean value back to its negation (two-way binding).
/// </summary>
/// <param name="value">The boolean 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 negated boolean value.</returns>
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return false;
}
}