PowerToys/Wox/Converters/ImagePathConverter.cs

32 lines
982 B
C#
Raw Normal View History

using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;
using System.Windows.Media.Imaging;
2014-07-14 19:03:52 +08:00
using Wox.Helper;
namespace Wox.Converters
{
public class ImagePathConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
2014-02-20 09:34:30 +08:00
if (values[0] == null) return null;
2014-07-14 19:03:52 +08:00
string relativePath = values[0].ToString();
string pluginDirectory = values[1].ToString();
2014-07-14 19:03:52 +08:00
string fullPath = Path.Combine(pluginDirectory, relativePath);
2014-02-20 18:26:01 +08:00
2014-07-14 19:03:52 +08:00
if (relativePath.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
2014-02-28 23:21:01 +08:00
{
2014-07-14 19:03:52 +08:00
return new BitmapImage(new Uri(relativePath));
2014-02-28 23:21:01 +08:00
}
2014-07-14 19:03:52 +08:00
return ImageLoader.Load(fullPath);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
}