We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Getting the name of the image from SfCrousel

Hi,

I have a button on my page which when I click, I wish to share the current carousel image to Facebook.  I have sorted out the share bit by using Xamarin essentials.  I have tested this with just hardcoding the image name.

What I wish to know is how to get the image name from the Carousel.  I have worked out how to get the index.  I have tried various options, searched the forums here and searched the Internet, but cannot find the solution.  I think I am missing the obvious.  Any help would be appreciated.

 async public void Handle_Clicked(object sender, EventArgs e)
        {
            var fn = MainCarouselView.SelectedIndex;


              //await DisplayAlert("Index",fn.ToString(), "OK");


            await Share.RequestAsync(new ShareFileRequest
            {
             Title = Title,
              File = new ShareFile(fn.ToString())
            });
        }

The following is the list that the Carousel is based on.  Note: I cannot use the list order as they are added in a random order to the grid by using a Guid.


        public BirthCarousel()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);




            List<string> imageName = new List<string>();

            {
                imageName.Add("birth01.jpg");
                imageName.Add("birth02.jpg");
                imageName.Add("birth03.jpg");
                imageName.Add("birth04.jpg");
                imageName.Add("birth05.jpg");
                imageName.Add("birth06.jpg");
                imageName.Add("birth07.jpg");
                imageName.Add("birth08.jpg");
                imageName.Add("birth09.jpg");
                imageName.Add("birth10.jpg");
                imageName.Add("birth11.jpg");
                imageName.Add("birth12.jpg");
                imageName.Add("birth13.jpg");
                imageName.Add("birth14.jpg");
                imageName.Add("birth15.png");
            }



            imageName = imageName.OrderBy(o => Guid.NewGuid().ToString()).ToList();


        var idaysopened = Helpers.Settings.DaysOpened;

            if (idaysopened > 12)
            {
                idaysopened = 13;
    }



            List<string> imageName1 = new List<string>();
            {
                imageName1.AddRange(imageName.Take(idaysopened + 3));
                imageName1.Add("04forpages.png");
            }

            MainCarouselView.ItemsSource = imageName1;


3 Replies

MK Muneesh Kumar G Syncfusion Team July 9, 2019 11:43 AM UTC

Hi Julie Misson, 
 
Greetings from Syncfusion.  
 
We have checked your requirement "Getting the name of the image from SfCarousel" from our side and prepared a sample for that based on the provided code. In this sample, we get a selected item image name by using carousel SelectedIndex property value. Please find the sample from the below link. 
 
 
If the provided sample is not suitable for your requirement means, please provide more detail about your requirement. It will help us to provide an appropriate solution on this. 
  
Regards,  
Muneesh Kumar G.  
 



JM Julie Misson August 1, 2019 08:49 AM UTC

Thanks,  worked perfectly.


MK Muneesh Kumar G Syncfusion Team August 1, 2019 08:54 AM UTC

Hi Julie Misson,  
 
Thanks for the update. 
  
We are glad to know that the given solution works. Please let us know if you need any further assistance. 
 
Thanks,   
Muneesh Kumar G.   
 


Loader.
Live Chat Icon For mobile
Up arrow icon