2016-11-13 120 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; }