25 lines
705 B
C#
25 lines
705 B
C#
using System;
|
|
using System.Globalization;
|
|
using Avalonia;
|
|
using Avalonia.Data.Converters;
|
|
|
|
namespace DelauneyTriangulation.Models;
|
|
|
|
public class Converters
|
|
{
|
|
|
|
}
|
|
|
|
public sealed class EmptyStringIntConverter : IValueConverter
|
|
{
|
|
public static readonly EmptyStringIntConverter Instance = new();
|
|
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value?.ToString();
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
var s = value as string;
|
|
if (string.IsNullOrWhiteSpace(s)) return 0;
|
|
return int.TryParse(s, NumberStyles.Integer, culture, out var n) ? n : 0;
|
|
}
|
|
} |