advanced-calculator/src/AdvancedCalculator/Converters/BoolToGridLengthConverter.cs
2025-08-26 23:24:50 -05:00

28 lines
847 B
C#

using System;
using Avalonia.Data.Converters;
using Avalonia;
using Avalonia.Controls;
namespace AdvancedCalculator.Converters;
public class BoolToGridLengthConverter : IValueConverter
{
public static readonly BoolToGridLengthConverter Instance = new();
public object? Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo? culture)
{
var isOpen = value is bool b && b;
// Return star when true, otherwise zero pixels
return isOpen ? new GridLength(1, GridUnitType.Star) : new GridLength(0, GridUnitType.Pixel);
}
public object? ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo? culture)
{
if (value is GridLength gl)
{
return gl.Value > 0;
}
return false;
}
}