PowerToys/Wox/Converters/ImagePathConverter.cs
2014-07-14 19:03:52 +08:00

32 lines
982 B
C#

using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Wox.Helper;
namespace Wox.Converters
{
public class ImagePathConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] == null) return null;
string relativePath = values[0].ToString();
string pluginDirectory = values[1].ToString();
string fullPath = Path.Combine(pluginDirectory, relativePath);
if (relativePath.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
{
return new BitmapImage(new Uri(relativePath));
}
return ImageLoader.Load(fullPath);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
}