2014-02-19 22:50:15 +08:00
|
|
|
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;
|
2014-02-19 22:50:15 +08:00
|
|
|
|
2014-05-24 16:06:09 +08:00
|
|
|
namespace Wox.Converters
|
2014-02-19 22:50:15 +08:00
|
|
|
{
|
|
|
|
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();
|
2014-02-19 22:50:15 +08:00
|
|
|
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);
|
2014-02-19 22:50:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|