FileToImageSourceConvert.cs 930 B

12345678910111213141516171819202122232425262728293031
  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. using System.Windows.Media.Imaging;
  9. namespace PDF_Office.DataConvert
  10. {
  11. /// <summary>
  12. /// 文件绝对路径 转ImageSource 转换器
  13. /// </summary>
  14. public class FileToImageSourceConvert : IValueConverter
  15. {
  16. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  17. {
  18. if(!string.IsNullOrEmpty((string)value)&&System.IO.File.Exists((string)value))
  19. {
  20. return new BitmapImage(new Uri((string)value, UriKind.Relative));
  21. }
  22. return null;
  23. }
  24. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  25. {
  26. throw new NotImplementedException();
  27. }
  28. }
  29. }