在一些令人沮丧的尝试之后,使用了
。
<Image Source="pack://application:,,,/{Binding ChannelInfo/ChannelImage}">
并且
<Image Source="pack://siteoforigin:,,,/{Binding ChannelInfo/ChannelImage}">
并且
<Image Source="/{Binding ChannelInfo/ChannelImage}">
我通过自己实现转换器来解决这个问题:
C# 部分:
public class MyImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string path= (string)value;
try
{
if (path.Length > 0 && path[0] == System.IO.Path.DirectorySeparatorChar
|| path.Length > 1 && path[1] == System.IO.Path.VolumeSeparatorChar)
return new BitmapImage(new Uri(path));
return new BitmapImage(new Uri(System.IO.Directory.GetCurrentDirectory() + System.IO.Path.DirectorySeparatorChar + path));
}
catch (Exception)
{
return new BitmapImage();
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
XAML方面:
<UserControl.Resources>
<local:ImageConverter x:Key="MyImageConverter" />
(...)
</UserControl.Resources>
<Image Source="{Binding Products/Image, Converter={StaticResource MyImageConverter}}">
干杯,
塞尔吉奥