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>
|
2026-08-13 09:49:27 +02:00
|
|
|
public sealed class NegateBoolConverter : IValueConverter
|
2026-08-10 14:45:47 +02:00
|
|
|
{
|
2026-08-13 09:49:27 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-13 09:49:27 +02:00
|
|
|
/// <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;
|
|
|
|
|
}
|
|
|
|
|
}
|