Files
PropertyGrid/Avalonia.PropertyGrid/Converters/NegateBoolConverter.cs
T

46 lines
1.5 KiB
C#
Raw Normal View History

2026-08-10 14:45:47 +02:00
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
2026-08-10 14:45:47 +02:00
{
/// <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>
2026-08-10 14:45:47 +02:00
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>
2026-08-10 14:45:47 +02:00
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return false;
}
}