protected override void OnAppearing() { base.OnAppearing(); if (!string.IsNullOrWhiteSpace(ftpurl.ToString())) { flexLayout.Children.Clear(); fileslist = new List <string>(); var path = ftpurl.ToString().Clone(); string[] files = ftpHelper.GetFilesDetailList(path.ToString()); string localpath = "/storage/emulated/0/Pictures/Stock6/"; if (!Directory.Exists(localpath)) { Directory.CreateDirectory(localpath); } if (files != null) { Device.BeginInvokeOnMainThread(async() => { foreach (var q in files) { int Mindex = q.IndexOf("M"); string str = q.Substring(Mindex + 1).Trim(); int index = str.IndexOf(" "); string file = str.Substring(index).Trim(); string localfilename = localpath + file; models.Add(new ImageModel(localfilename, 0, file, file.Substring(file.IndexOf('.')))); CachedImage cachedImage = new CachedImage { Source = UriImageSource.FromStream(() => ftpHelper.Download(path.ToString() + file)), WidthRequest = 120, HeightRequest = 120, Aspect = Aspect.AspectFill, DownsampleToViewSize = true, }; TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += async(sender, args) => { //image.Source = cachedImage.Source; //image.IsVisible = true; PhotoBrowserModel browserModel = new PhotoBrowserModel { ActionButtonPressed = (i) => { PhotoBrowserModel.Close(); } }; browserModel.Photos = new List <ImageModel>(); await Task.Run(() => { foreach (var s in models) { browserModel.Photos.Add(new ImageModel(Com.Facebook.Common.Util.UriUtil.GetUriForFile(new Java.IO.File(s.Path)).ToString(), 0, "", "")); } }); browserModel.StartIndex = Array.IndexOf(files, q); browserModel.Show(); }; cachedImage.GestureRecognizers.Add(tapGestureRecognizer); flexLayout.Children.Add(cachedImage); } await Task.Run(() => { foreach (var t in models) { Stream stream = ftpHelper.Download(path.ToString() + t.Name); StreamToFile(stream, t.Path); } }); }); } ftpurl = new StringBuilder(); } }