ToolSizeToIntConverter.cs 813 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Data;
  8. namespace PixiEditor.Helpers
  9. {
  10. [ValueConversion(typeof(string), typeof(int))]
  11. class ToolSizeToIntConverter : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. return string.Format("{0} {1}", value, "px");
  16. }
  17. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  18. {
  19. if (string.IsNullOrWhiteSpace(value as string)) return null;
  20. string slicedString = value.ToString().Split(' ').First();
  21. return int.Parse(slicedString);
  22. }
  23. }
  24. }