StringToIntConverter.cs 671 Bytes
using System;
using System.Globalization;
using System.Windows.Data;

namespace HHECS.WinCommon.ValueConverter
{
    public class StringToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value?.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (int.TryParse(value?.ToString(), out int temp) == true)
            {
                return temp;
            }
            else
            {
                return null;
            }
        }
    }
}