好的,我正在创建的图像列表(使用列表框),左侧是缩略图,右侧是图像标题。我的XAML设置是这样的:将XAML DataTemplate中的图像源绑定到Silverlight 4中的URI
<ListBox HorizontalAlignment="Left" Margin="6,6,0,6" Name="CurrentPhotos" Width="184" SelectionChanged="CurrentPhotos_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Converter={StaticResource FilePathConverter}}" />
<sdk:Label Content="{Binding Title}"></sdk:Label>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我得在App.xaml中定义的FilePathConverter键和代码设置:
public class FilePathConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (targetType == typeof(string))
{
return (value as PhotoSummary).FullThumbPath();
}
else
{
return (value as PhotoSummary).Thumb();
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
有两个断点转换和ConvertBack方法。 ConvertBack永远不会被触发(所以没有例外等),并且在Convert方法中,Thumb正确地返回(字符串输入是由于某些测试原因而留下的,并且目前还没有使用,它不会被触发),并且Thumb扩展方法是this :
public static object Thumb(this PhotoSummary ps)
{
Uri uri = new Uri("http://" + Settings.Host + "/Content/Thumbs/" + ps.Uploaded.Year + "/" + ps.Uploaded.Month + "/" + ps.ID + ".jpg", UriKind.Absolute);
return new BitmapImage(uri);
}
这个被调用,并且Uri被正确构建(测试了几次)。但是,当我运行该应用程序时,该列表仅包含照片的标题,并且没有图像。所有图像都很小(它们只是大拇指),本地文件,所以它们需要立即加载,因此它也不是加载问题。但它好像没有图像标签那里。它只显示照片的标签。转换器正在工作,Uri是正确的,根本没有错误,但没有图像显示。
有什么建议吗?
您是否尝试过使用小提琴手,以验证是否Silverlight是实拍的图像,如果真的返回的图像的请求显示? – MerickOWA
试过了,没有,没有请求。我可以看到来自同一应用程序的其他请求(服务调用),它们工作,我可以在提琴手中看到它们,但没有图像请求。很奇怪。 –
Hrm奇怪,也许尝试订阅图像上的ImageFailed事件,看看解析Uri时是否有一些问题阻止下载开始。 – MerickOWA