diff --git a/src/AdvancedCalculator/Converters/WidthToBooleanConverter.cs b/src/AdvancedCalculator/Converters/WidthToBooleanConverter.cs new file mode 100644 index 0000000..6efa5f6 --- /dev/null +++ b/src/AdvancedCalculator/Converters/WidthToBooleanConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Globalization; +using Avalonia.Data.Converters; + +namespace AdvancedCalculator.Converters; + +// Returns true if width (double) is less than the provided threshold (parameter), +// otherwise false. Default threshold is 640 when parameter is null or invalid. +public class WidthToBooleanConverter : IValueConverter +{ + public static readonly WidthToBooleanConverter Instance = new(); + + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo? culture) + { + if (value is double width) + { + double threshold = 640; + if (parameter is double p) + threshold = p; + else if (parameter is string s && double.TryParse(s, NumberStyles.Number, CultureInfo.InvariantCulture, out var parsed)) + threshold = parsed; + + return width < threshold; + } + return false; + } + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture) + => throw new NotSupportedException(); +} + diff --git a/src/AdvancedCalculator/Views/MainView.axaml b/src/AdvancedCalculator/Views/MainView.axaml index 71ffac9..35b2c61 100644 --- a/src/AdvancedCalculator/Views/MainView.axaml +++ b/src/AdvancedCalculator/Views/MainView.axaml @@ -10,92 +10,131 @@ x:DataType="vm:MainViewModel"> + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +