【发布时间】:2013-03-01 15:09:59
【问题描述】:
在 Windows Metro Apps (C#) 中,我使用 ValueConverter 传递 Image-Uri,如下所示:
public class ProfileImage : IValueConverter {
public Object Convert(Object value, Type targetType, Object parameter, String language) {
if (value == null) {
return "Common/images_profile/user.png";
}
return "ms-appdata:///local/" + (String)value;
}
public Object ConvertBack(Object value, Type targetType, Object parameter, String language) {
return value;
}
}
XAML:
<Image x:Name="profileImage" Height="80" Width="80" Source="{Binding Path, Converter={StaticResource ProfileImage}}"/>
图像正在异步下载到 localFolder。
我想在 Windows Phone 8 上使用它 - 但它没有显示任何图像。
var localFolder = ApplicationData.Current.LocalFolder;
StorageFile myFile = await localFolder.CreateFileAsync(
UID + ".jpg",
CreationCollisionOption.FailIfExists);
using (var s = await myFile.OpenStreamForWriteAsync()) {
s.Write(imageBytes, 0, imageBytes.Length);
}
用于将图像写入LocalStorage。
如果value 中没有内容,则Common/images_profile/user.png 中的图像正在正常显示。这个在包里,不在本地文件夹里。
我需要知道我必须使用哪种格式作为返回参数来显示图像。
【问题讨论】:
标签: c# wpf image xaml windows-phone-8