I have a listview in my UWP (Windows 10) application. Ideally it will load 100 items when application starts.
When list is scrolled to bottom i.e. to the last item in listview, API call will go & will load another 100 items & so on..
Here is my code :
<ListView x:Name="lstSuggestions" Height="200" Width="250" Foreground="#333eb4" HorizontalAlignment="Left" Margin="60,10" SelectionChanged="lstSuggestions_SelectionChanged"></ListView>
following call binds the listview (first 100 items on app start) :
public async void GetData(string Id, string limit)
{
string mainUrlForSuggestions = ApiUrl + "&id=" + d;
string finalSelCharas = "";
using (var httpClient = new HttpClient())
{
var dataUri = await httpClient.GetStringAsync(mainUrlForSuggestions);
JsonObject jsonObject = JsonObject.Parse(dataUri.ToString());
JsonArray jsonArray = jsonObject["payload"].GetArray();
foreach (JsonValue groupValue in jsonArray)
{
JsonObject groupObject = groupValue.GetObject();
lstSuggestionsAdd.Add(new SuggestedWords { Name = groupObject.GetNamedString("sug_name"), ID = groupObject.GetNamedString("id") });
}
lstSuggestions.ItemsSource = lstSuggestionsAdd;
}
}
on app start limit is 100, once list reaches to an end, it must set limit to 200 or next 100 items and make an API call again.
I tried to achieve this with pointerEntered event. But, couldn't achieve the said functionality as it only matches the height assigned to listview with pointer height, so that wont work as scrollviewer height can vary. I even tried to get access to scrollviewer, but couldn't!
I have also referred following URL's : How do I allow a UWP ListView to scroll past the last item? && Detect when WPF listview scrollbar is at the bottom? && https://social.msdn.microsoft.com/Forums/windows/en-US/63b4b530-61d8-477f-af96-87e33260c919/uwa-how-to-detect-the-end-and-the-start-of-listview-and-load-more-data-items?forum=wpdevelop
But none of them actually worked in my case.
I tried to find an event to achieve this functionality, but didn't find any.
Can anyone give an idea about how to detect if listview scrolling reached to an end (last item in the listview)???
Note that i am working on windows 10 UWP application & not win 8
lstSuggestions_PointerEntered
look like? 2) is it being called? (test it with a break point) 3) isn't there some ononitem_visible
-like event? – StefanlstSuggestions_PointerEntered
is called whenever the pointer is moved to listview area/section. It just captures whether the pointer is in listview UI area – acelstSuggestions_PointerEntered
or not. You can refer to this answer : [Detect when WPF listview scrollbar is at the bottom? ] (stackoverflow.com/a/37430977/8024811) however it doesn't helped in my case – ace