question

AnasGuibene avatar image
0 Votes"
AnasGuibene asked AnasGuibene answered

How to fix Listview not reaching the last item when scrolling

Hello, I have a listview that contains messages (refresh every 5 seconds)

I tried this code to make my listview start showing the last message `

 if (MessagesListView.ItemsSource != null)
                     {
                         lastItem =MessagesListView.ItemsSource.Cast<object().LastOrDefault();
                            
                         MessagesListView.ScrollTo(lastItem,ScrollToPosition.End, false);
                     }

When I open the page the listview scrolls but it doesn't reach the last item.
Although after the refresh, the listview scrolls to the last item successfully.


dotnet-xamarin
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AnasGuibene ,I did a test, but I couldn't reproduce this problem. Could you please post a basic demo to github or onedriver so that we can test on our side?
Note: If you want to make the whole last item visible, you can try to change code to : MessagesListView.ScrollTo(lastItem, ScrollToPosition.MakeVisible, true);

0 Votes 0 ·

This is a screenshot when I start the chat page :
the listview scrolls but it stop before the last item shows

oCrWlv3


0 Votes 0 ·
AnasGuibene avatar image
0 Votes"
AnasGuibene answered

@JessieZhang-2116 i just found the solution
the problem was in the scrollview
I deleted the scroll view and all is good

 <ScrollView BackgroundColor="Transparent">
                     <ListView
                     x:Name="MessagesListView" 
                     ItemTemplate="{StaticResource MessageTemplateSelector}" 
                     ItemsSource="{Binding ListMessages}" 
                     HasUnevenRows="True"
                     SeparatorVisibility="None"
                     SelectionMode="None"
                     IsEnabled="True"/>
                 </ScrollView>
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered JessieZhang-2116 commented

Hello,


Welcome to our Microsoft Q&A platform!

According to your screenshot ,I found that the below bar should have overlayed the content of your listview below . So, that's the problem.

In fact, the listview has reached the last item when scrolling while using following code:

      if (MessagesListView.ItemsSource != null)
                  {
                      lastItem =MessagesListView.ItemsSource.Cast<object().LastOrDefault();
                            
                      MessagesListView.ScrollTo(lastItem,ScrollToPosition.End, false);
                  }

But the last sevaral items have been overlayed by the above float bar

96211-image.png

As a test, I simulated such condition, and set the color of the bottom part to transparent color, the result is:

96184-image.png

From above image, we can find that some part of the listview has been overlayed by the bottom part.

So, if you want to the last item of your listview could be visible to users, you can put your listview on top of your the bottom part not overlayed by the bottom part.

Best Regards,


Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.



Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (27.4 KiB)
image.png (114.4 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AnasGuibene, I have not heard from you for a couple of days. Please let me know if there is anything that I can help here.

0 Votes 0 ·

hi @JessieZhang-2116

How can i put my listview on the part ! i cannot understand what you mean

0 Votes 0 ·

I mean that the bottom part of the list has been overlayed by the bottom part(the input box). You can put the listView and the bottom part(the input box) into a `StackLayout instead of having the input box overlay the ListView..

0 Votes 0 ·