How to choose images for each list view item?

YaserYaser Member ✭✭✭
edited July 2019 in Xamarin.Forms

async void AddPic_Clicked(object sender, EventArgs e)
{
try
{
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
else
{
await CrossMedia.Current.Initialize();

                var mediaoption = new PickMediaOptions()
                {
                    PhotoSize = PhotoSize.Medium
                };

                var Selectedimagefile = await CrossMedia.Current.PickPhotoAsync(mediaoption);

                if (Selectedimagefile == null)
                {
                    await DisplayAlert("errrore", "ok", "ok");
                    return;
                }


                var ImageStream = Selectedimagefile.GetStream();



                using (var fileStream = new FileStream(fileName, FileMode.Create))
                {
                    ImageStream.CopyTo(fileStream);
                }


                //   var imagesoruce = ImageSource.FromStream(Selectedimagefile.GetStream());

                imgTemplateImages.Source = ImageSource.FromFile(fileName);



            }
        }
        catch
        {
            await DisplayAlert("Alert", "Something Went Wrong", "Ok");
        }

in list view

i take one image from galley how can i take image for each list view item .

Answers

  • RezaShabanRezaShaban USMember ✭✭
    edited July 2019

    you can set unique id for your button ClassId property and on click event get that value and find item from your list and set photo for that list item

    sample code:
    Xaml:
    <Button ClassId="{Binding UniqueID}" clicked="btn_Clicked"/>
    c# code=> (btn_Clicked):
    var id = ((Button)sender).ClassId; list.FirstOrDefault(x => x,UniqueID == id).Photo = takedPhoto;

  • YaserYaser Member ✭✭✭

    @RezaShaban said:
    you can set unique id for your button ClassId property and on click event get that value and find item from your list and set photo for that list item

    sample code:
    Xaml:
    <Button ClassId="{Binding UniqueID}" clicked="btn_Clicked"/>
    c# code=> (btn_Clicked):
    var id = ((Button)sender).ClassId; list.FirstOrDefault(x => x,UniqueID == id).Photo = takedPhoto;

    it have this error

    The name 'takedPhoto and UniqueID' does not exist in the current context

  • RezaShabanRezaShaban USMember ✭✭

    It was a code example and shows you the way, you should use your own property

  • YaserYaser Member ✭✭✭
    > @RezaShaban said:
    > It was a code example and shows you the way, you should use your own property

    I do not understand
Sign In or Register to comment.