與
<Image Source="pack://application:,,,/{Binding ChannelInfo/ChannelImage}">
和
嘗試一番折騰次後
<Image Source="pack://siteoforigin:,,,/{Binding ChannelInfo/ChannelImage}">
和
<Image Source="/{Binding ChannelInfo/ChannelImage}">
我解決了這個實現自己的轉換ER:
C#的一面:
public class MyImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string path= (string)value;
try
{
//ABSOLUTE
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));
//RELATIVE
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}}">
乾杯,
塞爾吉奧
當然 - 的作品 - THX!找不到找到應用程序文件夾的好方法,所以現在感覺有點怪異..在.Net中是否有GetApplicationFolder()?找不到一個..但不應該相對路徑引用以某種方式工作?然後這些將相對於應用程序根文件夾?沒有? – stiank81 2009-09-18 20:03:48
嘗試Path.GetDirectoryName(Assembly.GetExecutingAssembly()。位置); – 2009-09-18 20:05:43
這給了我一樣的,我正在使用,「Path.GetFullPath(」。「),但我想後者取決於工作文件夾,所以隨着你的建議,我得到了更多的問題,但這個,但我會弄明白的。Thx請注意! – stiank81 2009-09-18 20:38:34