ImagePathToImageSourceConverter.cs 904 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Data;
  9. using System.Windows.Media.Imaging;
  10. namespace MeterVision.Converter
  11. {
  12. public class ImagePathToImageSourceConverter : IValueConverter
  13. {
  14. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  15. {
  16. string imagePath = value as string;
  17. if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath) )
  18. {
  19. return new BitmapImage(new Uri(imagePath, UriKind.RelativeOrAbsolute));
  20. }
  21. return null;
  22. }
  23. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  24. {
  25. throw new NotImplementedException();
  26. }
  27. }
  28. }