简体   繁体   English

在Xamarin表单列表视图中显示与URL关联的图像

[英]Displaying images associated with url's in a xamarin forms listview

I am building a mobile app with xamarin forms. 我正在使用xamarin表单构建一个移动应用程序。 I have a listview that will store description about a url. 我有一个listview,它将存储有关url的描述。 I want to be able to display the icons or images that are tied to the url without saving images in my database. 我希望能够显示与URL绑定的图标或图像,而无需在数据库中保存图像。 When you text a url to someone, am image shows with the url. 当您向某人发送网址时,会显示带有该网址的图片。 Any ideas how this can be done? 任何想法如何做到这一点? I have been researching and no luck. 我一直在研究,没有运气。

hope this helps , specify a UriImage source for your image, set the uri property to the image url 希望对您有所帮助,为您的图像指定UriImage源,将uri属性设置为图像url

               <Image 
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand"
                    Aspect="AspectFit">
                    <Image.Source>
                        <UriImageSource Uri="{Binding EventImage}" 
                            CacheValidity="3" 
                            CachingEnabled="true"/>
                    </Image.Source>
                </Image>

to display in Image in a ListView, use an ImageCell 要在ListView中的图像中显示,请使用ImageCell

<ImageCell ImageSource="{Binding FaviconUrl}" Text="{Binding Name}" />

You'll have to add a property to your model that will determine (or guess) the correct url for the site's favicon. 您必须在模型中添加一个属性,该属性将确定(或猜测)该网站的收藏夹图标的正确URL。

You can get the fav-icon using the Google S2 converter . 您可以使用Google S2转换器获取收藏夹图标。

For eg: https://www.google.com/s2/favicons?domain=yahoo.com : 例如: https : //www.google.com/s2/favicons?domain=yahoo.com 图标

To get it to work with your image control, this should technically work: 要使其与图像控件一起使用,从技术上讲,这应该可以工作:

<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>

Or, 要么,

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM