【发布时间】:2018-07-27 06:54:08
【问题描述】:
我有一个带有来自 Internet 的图像的 Xamarin ListView。我会显示一个默认图像(来自嵌入式资源),如果存在,则显示来自 url 的图像。
我已尝试使用此代码,但仅适用于 UriImageSource,不适用于嵌入式资源:
<ListView ItemsSource="{Binding Data}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Image>
<Image.Source>
<!-- does not works
<ImageSource>
{utils:ImageResource Namespace.Assets.img-placeholder.png}
</ImageSource>
-->
<UriImageSource Uri="{Binding ImageUri}"></UriImageSource>
</Image.Source>
</Image>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如果我使用
<Image Source="{utils:ImageResource Namespace.Assets.img-placeholder.png}" />
这可以显示嵌入的资源默认图像
型号:
public Uri ImageUri => Image != null ?
new Uri($"http://www.example.com/{Image}")
: null;
有什么帮助吗?谢谢
【问题讨论】:
标签: xaml binding xamarin.forms