qamp/Qrakhen.TilingFrames/Converters/BetaRatioConverter.cs

31 lines
1.1 KiB
C#

using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace Qrakhen.TilingFrames.Converters
{
public class BetaRatioConverter : MarkupExtension, IValueConverter
{
public override object ProvideValue(IServiceProvider serviceProvider) => this;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double ratio) {
if (ratio >= 1)
return new GridLength(0, GridUnitType.Star);
if (ratio >= .5)
return new GridLength(1, GridUnitType.Star);
else if (ratio <= double.Epsilon)
return new GridLength(1, GridUnitType.Star);
return new GridLength((1 - ratio) / ratio, GridUnitType.Star);
}
throw new ArgumentException($"Expected value to be ratio (double), god {value} instead.");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
}