以xamarin形式列表视图显示与url相关的图像
我正在用xamarin形式构建移动应用程序。我有一个列表视图,将存储关于URL的描述。我希望能够显示绑定到url的图标或图像,而不会将图像保存到我的数据库中。当你给某人发短信的时候,图片显示的是url。任何想法如何做到这一点?我一直在研究,没有运气。以xamarin形式列表视图显示与url相关的图像
希望这有助于指定UriImage源图像,设置uri属性的图像URL
<Image
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Aspect="AspectFit">
<Image.Source>
<UriImageSource Uri="{Binding EventImage}"
CacheValidity="3"
CachingEnabled="true"/>
</Image.Source>
</Image>
属性我不存储图像。我希望能够从url中提取图片 – user2320476
这段代码是否会从url中提取图片并将其存储在列表视图中? – user2320476
是在你的视图模型中创建一个属性,并使用它来代替EventImage –
在ListView来显示图像,使用的ImageCell
<ImageCell ImageSource="{Binding FaviconUrl}" Text="{Binding Name}" />
你必须向你的模型添加一个属性,以确定(或猜测)该网站的图标的正确URL。
我确实有所有的网址存储在我的数据库正在拉动。我也有一个名为description的字段。我想在我的列表视图中显示描述和图标网址 – user2320476
我建议你添加一个属性到你的模型中,它将根据你已经在数据库中的url返回的图标网址。 – Jason
www.yahoo.com可以成为faviconUrl吗? – user2320476
您可以使用Google S2 converter获取fav图标。
对于如: https://www.google.com/s2/favicons?domain=yahoo.com:
让它与你的图像控制工作,这应该在技术上的工作:
<ImageCell Text="{Binding DomainUrl}">
<ImageCell.ImageSource>
<UriImageSource Uri="{Binding Path=DomainUrl, StringFormat='https://www.google.com/s2/favicons?domain={0}'}"
CacheValidity="1"
CachingEnabled="true"/>
</ImageCell.ImageSource>
</ImageCell>
或者,
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<Image HorizontalOptions="Center" VerticalOptions="Center">
<Image.Source>
<UriImageSource Uri="{Binding Path=DomainUrl, StringFormat='https://www.google.com/s2/favicons?domain={0}'}"
CacheValidity="1"
CachingEnabled="true"/>
</Image.Source>
</Image>
<Label Text="{Binding Path=DomainUrl}" />
</StackLayout>
</ViewCell>
你的意思favicon?或者,如果没有,你谈论什么的具体例子会有帮助。 – Jason
是的favicon是我的意思。这样我就可以将它拉出来并在列表视图中显示它的描述 – user2320476
你读过了它的[docs](https://en.wikipedia.org/wiki/Favicon)吗?你到底在做什么? – Jason