Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How I can DataBind image ?

$
0
0

Hi everybody,

I have a problem to bind an image in a XAML page.

I've created a class "Patrimoine" that has two properties:

    public class Patrimoine
        {
            public string Titre { get; set; }
            public string Image { get; set; }
        }

And I have a MasterDetailPage "page1" that instantiates a list of objects "Patrimoine":

namespace AppPat.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Page1 : ContentPage
    {
        public List<Patrimoine> ListePatrimoine = new List<Patrimoine>();

        public Page1()
        {
            InitializeComponent();
            // Setting our list to be ItemSource for ListView in MainPage.xaml
            listePatrimoine.ItemsSource = ListePatrimoine;

            var Eglise = new Patrimoine() { Titre = "Eglise",  Image = "testimage.png" };
            ListePatrimoine.Add(Eglise);
        }

        private async void listePatrimoine_ItemSelectedAsync(object sender, SelectedItemChangedEventArgs e)
        {
            if (listePatrimoine.SelectedItem != null)
            {
                var detailpage = new DetailPage();
                detailpage.BindingContext = e.SelectedItem as Patrimoine;
                listePatrimoine.SelectedItem = null;
                await Navigation.PushModalAsync(detailpage);
            }
        }
    }
}

I have a DetailPage which presents the properties of the class "Patrimoine":

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="AppPat.Views.DetailPage">
    <ContentPage.Content>
        <StackLayout HorizontalOptions="Center" VerticalOptions="Center">
            <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
                <Image  Source="{Binding Image}"/>


            </StackLayout>
            <StackLayout Orientation="Horizontal">
                <Label Text="Nom:" FontSize="Medium" HorizontalOptions="FillAndExpand" />
                <Label Text="{Binding Titre}" FontSize="Medium" FontAttributes="Bold" />
                <Label Text="Année:" FontSize="Medium" HorizontalOptions="FillAndExpand" />
                <Label Text="{Binding Annee}" FontSize="Medium" FontAttributes="Bold" />
            </StackLayout>

            <Button x:Name="dismissButton" Text="Dismiss" Clicked="dismissButton_ClickedAsync" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

But the image does not appear.
I do not want to integrate the image by integrating a text like: testimage.png (https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images).

I want to bind the image in XAML this way: Image Source="{Binding Image}

Can you help me please ?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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