using Avalonia.Data.Converters; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShakerApp.Convert { public class MathAddConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { // For add this is simple. just return the sum of the value and the parameter. // You may want to validate value and parameter in a real world App if (value is double v && double.TryParse(parameter!.ToString(), out var val)) { return v + val; } return 0; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { // If we want to convert back, we need to subtract instead of add. if (value is double v && double.TryParse(parameter!.ToString(), out var val)) { return v - val; } return 0; } } public class SubtractionConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { // For add this is simple. just return the sum of the value and the parameter. // You may want to validate value and parameter in a real world App if (value is double v && double.TryParse(parameter!.ToString(), out var val)) { return v - val; } return 0; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { // If we want to convert back, we need to subtract instead of add. if (value is double v && double.TryParse(parameter!.ToString(), out var val)) { return v + val; } return 0; } } public class MultiConverter : IValueConverter { public static MultiConverter Instance { get; } = new MultiConverter(); public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if(value is double v && double.TryParse(parameter!.ToString(),out var val)) { return v * val; } return 0; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotImplementedException(); } } }