- Home
- Forum
- Xamarin.Forms
- Update item depending the scroll and the visibility of my items.
Update item depending the scroll and the visibility of my items.
Hello,
I have a list view with many items, I wanted to load my list view items with a default image or load the first items displayed on the screen.
Then depending the scroll and the items visible on the screen, I would like to update each items visible with the related image stream.
I tried to made a quick sample but it doesn't work at all, my app is crashing : "Sharing violation on path ...." ,when I the scrolling event is raised.
Any idea to make this auto-updating listView depending the visibility of each items on the UI ?
public partial class MyClass : ContentPage
{
private readonly ThumbnailsViewModel thumbnailsViewModel;
private readonly FileInfo fileInfo;
IListlist = new List ();
public MyClass (FileInfo fileInfo)
{
InitializeComponent();
this.fileInfo = fileInfo;
this.thumbnailsViewModel = new ThumbnailsViewModel(fileInfo);
VisualContainer visualContainer;
visualContainer = ThumbnailsListView.GetVisualContainer();
int numberOfPage = DependencyService.Get().GetAllPages(fileInfo.FullName);
int i = 0;
while (i < numberOfPage)
{
list.Add(new model { image = ImageSource.FromFile("award.png") });
i++;
}
ThumbnailsListView.ItemsSource = list;
var scrollview = ThumbnailsListView.GetScrollView();
scrollview.Scrolled += (sender, e) => Scrollview_Scrolled(sender, e, visualContainer);
}
private void Scrollview_Scrolled(object sender, ScrolledEventArgs e, VisualContainer vs)
{
VisibleLinesCollection visibleLineInfos = vs.ScrollRows.GetVisibleLines();
var first = visibleLineInfos.First();
int firstIndex = first.LineIndex;
int lastItemVisble = visibleLineInfos.Count;
int i = firstIndex;
while (i <= lastItemVisble)
{
MemoryStream stream = PdfToImage.FileToImage(fileInfo, i);
byte[] files = stream.ToArray();
var m = new model { image = ImageSource.FromStream(() => new MemoryStream(files)) };
list[i] = m;
i++;
}
}
}
public class model
{
public ImageSource image { get; set; }
}
SIGN IN To post a reply.
3 Replies
SS
SaiGanesh Sakthivel
Syncfusion Team
April 6, 2020 12:58 PM UTC
Hi Rayhane,
Thank you for contacting syncfusion support.
We have checked the reported query “Updating item depending on scroll view” from our end. We would like to inform that you can achieve your requirement by setting the INotifyPropertyChanged property in ViewModel class.
We hope this helps. Please let us know if you need further assistance.
Regards,
SaiGanesh Sakthivel
RA
Rayhane
April 9, 2020 01:37 PM UTC
After reading this post I just discoverd that sf List view was already using virtualization, the sample that I was trying to make is useless in this case.
Thank you for your help
LN
Lakshmi Natarajan
Syncfusion Team
April 10, 2020 12:30 PM UTC
Hi Rayhane,
Thank you for the update.
Yes. The SfListView is implemented using Virtualization concept.
Please let us know if you need any further assistance. As always we are happy to help you out.
Regards,
Lakshmi Natarajan
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
RA Rayhane
- Apr 4, 2020 06:16 PM UTC
- Apr 10, 2020 12:30 PM UTC