2016-11-13 127 views
1

我无法使用Xamarin Forms将图像绑定到UriImageSource。将图像绑定到URL Xamarin Forms XAML

我已经实现呈现文本的网格状列表中FlowListView但每个产品相关的图片没有显示。

有没有其他人有这个/知道如何解决它?

谢谢!

XAML:

 <flv:FlowListView.FlowColumnTemplate> 
      <DataTemplate> 
       <Grid Padding="3"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*" /> 
        </Grid.ColumnDefinitions> 


       <Image HeightRequest="100" > 
        <Image.Source> 
        <UriImageSource Uri="{Binding ProductImage}" /> 
        </Image.Source> 
        </Image> 

        <Label x:Name="Label" HorizontalOptions="Fill" HorizontalTextAlignment="Center" VerticalOptions="End" 
         BackgroundColor="Silver" Opacity="0.5" Text="{Binding ProductName}"/> 
       </Grid> 
      </DataTemplate> 
     </flv:FlowListView.FlowColumnTemplate> 

    </flv:FlowListView> 

视图模型:

public class vmProduct { 
     public vmProduct() { } 
/* removed other properties, constructors etc */ 
     public UriImageSource ProductImage { get; set; } 
     public string ProductName { get; set; } 
} 

当vmProduct被初始化

this.Products.Add(new vmProduct { ProductName = "Test", ProductImage = new UriImageSource { Uri = new Uri("https://upload.wikimedia.org/wikipedia/en/5/5f/Original_Doge_meme.jpg") } }); 

(在上述例子中, “测试” 将出现,但图像不会)

+1

@jzeferino明白了,谢谢! –

回答

2

由于您将UriImageSource绑定到Uri您的ViewModel属性必须是Uri。

变化public UriImageSource ProductImage { get; set; }public Uri ProductImage { get; set; }