Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to bind Images to URI

$
0
0

Hello again. This is a second try for my previous discussion that degenerate because I didnt know how to quote code. I would like to delete it but I dont know how to do.

So, I have a MVVM project that aim to display items on a listview. Every item contain an image and a name. For now the image point to a picture on internet, but my goal is to let it point an image from my storage on the cloud. My problem is when I hardcode the hyperlink on the XAML as source for the Image tag, the images are displayed but when I assign the same link, hardcoded to a variable of the ViewModel and then bind the XAML image to that variable the images are not displayed, although the items names binds correctly.

here is the code that work : the I replaced the hyperlink by HYPERLINK :smile:

<ContentPage.Content>
    <StackLayout>
        <ListView ItemsSource="{Binding ItemsList}"
                  ItemSelected="OnItemSelected" x:Name="ItemsListView" HasUnevenRows="True">
            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                     <StackLayout>
                        <Image Source="HYPERLINK" HorizontalOptions="FillAndExpand" 
                        Margin="1,3,1,3" WidthRequest="40" HeightRequest="40"></Image>
                        <Label Text="{Binding Name}" FontAttributes="Bold" />
                        <Label TextColor="DeepSkyBlue" Text="{Binding Label}" />
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>

And then when I replace HYPERLINK by the binding instruction below, images are not displayed :

<Image Source="{Binding ImageUri}" HorizontalOptions="FillAndExpand" 
                        Margin="1,3,1,3" WidthRequest="40" HeightRequest="40"></Image>

what I'm I doing wrong?
FYI my page inherit from a BasePage that set the ViewModel as BindingContext and the ItemList Collection is well initialised in that ViewModel. I checked in runtime that the Name and the URI are assigned for every Items. only the name is displayed, not the Image. so may be I dont bind the image correctly? how to do this well?

Thank you


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>