28 lines
847 B
C#
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;
|
|
}
|
|
}
|
|
|