123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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();
- }
- }
- }
|