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

Scroll to last item of SfListView

Hello,

I search for a equivalent method as the Xamarin.Forms ListView.ScrollTo(Object item, ScrollToPosition position, Boolean animated).

ListView.ScrollTo - Xamarin Documentation

I want to scroll to the last item of SfListView. Is there any way to do this?

Best regards
Luke

8 Replies

DB Dinesh Babu Yadav Syncfusion Team January 19, 2017 03:47 AM UTC

Hi Luke,   
   
Thank you for using Syncfusion products.   
   
You can achieve your requirement “Adjust scroll position programmatically in SfListView” by using ScrollToRowIndex method. The following code example illustrates to position the scroll viewer while initializing the SfListView.    
    
Code example[C#]:    
    
listView.Loaded += ListView_Loaded;    
    
private void ListView_Loaded(object sender, ListViewLoadedEventArgs e)    
{    
    (listView.LayoutManager as LinearLayout).ScrollToRowIndex(ViewModel.contactsinfo.Count);    
}    
    
    
For your reference, we have attached the sample also. Please find the sample link below,    
 
Regards,    
Dinesh Babu Yadav  



LU Luke January 19, 2017 08:59 PM UTC

Hi,

thank you for the fast answer. I try it.

Regards
Luke


DB Dinesh Babu Yadav Syncfusion Team January 20, 2017 04:39 AM UTC

Hi Luke,  
  
Thanks for the update.  
  
We will wait to hear from you.  
  
Regards,  
Dinesh Babu Yadav 



DP Dirk Prodi replied to Dinesh Babu Yadav April 12, 2017 12:18 PM UTC

Hi Luke,   
   
Thank you for using Syncfusion products.   
   
You can achieve your requirement “Adjust scroll position programmatically in SfListView” by using ScrollToRowIndex method. The following code example illustrates to position the scroll viewer while initializing the SfListView.    
    
Code example[C#]:    
    
listView.Loaded += ListView_Loaded;    
    
private void ListView_Loaded(object sender, ListViewLoadedEventArgs e)    
{    
    (listView.LayoutManager as LinearLayout).ScrollToRowIndex(ViewModel.contactsinfo.Count);    
}    
    
    
For your reference, we have attached the sample also. Please find the sample link below,    
 
Regards,    
Dinesh Babu Yadav  


(listView.LayoutManager as LinearLayout).ScrollToRowIndex

Hello,

How am I able to get the current RowIndex which is visible? For our use case we want to scroll by e.g. 10 items

Best regards,
Daniel



MK Muthu Kumaran Gnanavinayagam Syncfusion Team April 13, 2017 12:59 PM UTC

Hi Daniel, 
  
You can achieve your requirement “Visible index in the view in SfListView” by using theScrollRows.Changed event. The following code illustrates how to get the First visible index and Last visible index for the ListView items which are currently in the View whenever scroll. 
  
Code example:[C#] 
 
    VisualContainer visualContainer = listView.GetType().GetRuntimeProperties().First(p => p.Name == "VisualContainer").GetValue(listView) as VisualContainer; 
    scrollRows = visualContainer.GetType().GetRuntimeProperties().First(p => p.Name =="ScrollRows").GetValue(visualContainer) as ScrollAxisBase; 
    scrollRows.Changed += ScrollRows_Changed; 
  
private void ScrollRows_Changed(object sender, ScrollChangedEventArgs e) 
{ 
  var firstIndex= scrollRows.ScrollLineIndex; 
  var lastindex = scrollRows.LastBodyVisibleLineIndex; 
} 
  
For your reference we have attached the sample also. Please find the sample link below. 
  
  
Regards, 
G.Muthu Kumaran. 



MK Muthu Kumaran Gnanavinayagam Syncfusion Team November 8, 2017 01:39 PM UTC

Hi Bharathi, 
 
We have checked with the reported query and referred the attached screenshot from our side. You can achieve your requirement by loading the SfListView inside a Frame with its HasShadow property value set as ‘True’ as like below code example. 
 
Code example[XAML]: 
<ContentPage> 
    <Grid RowSpacing="0" BackgroundColor="#E5E4E2"> 
        <Grid.RowDefinitions> 
          <RowDefinition Height="Auto" /> 
        </Grid.RowDefinitions> 
         
        <Frame HasShadow="True" Margin="8,8,8,8" Padding="0,0,0,0"> 
        <sync:SfListView x:Name="listView" HeightRequest="220" ItemSize="100" 
                         SelectionMode="None" 
                         Orientation="Horizontal" 
                         ItemsSource="{Binding PizzaInfo}"> 
          <sync:SfListView.ItemTemplate> 
            <DataTemplate> 
              <Frame BackgroundColor="#ff8e02" Padding="2"> 
                                 
               <Grid RowSpacing="0" HorizontalOptions="Fill" VerticalOptions="Fill"> 
                  <Grid.RowDefinitions> 
                    <RowDefinition Height="*" /> 
                    <RowDefinition Height="20" /> 
                  </Grid.RowDefinitions> 
                  <Image Source="{Binding PizzaImage}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" /> 
                  <Label Grid.Row="1" Text="{Binding PizzaName}" 
                         LineBreakMode="WordWrap" 
                         HorizontalTextAlignment="Center" 
                         VerticalTextAlignment="Center" 
                         TextColor="#8f0100" 
                         FontAttributes="Bold"/> 
                </Grid> 
              </Frame> 
            </DataTemplate> 
          </sync:SfListView.ItemTemplate> 
        </sync:SfListView> 
      </Frame> 
    </Grid> 
</ContentPage> 
 
For your reference, we have attached the sample and screenshot in the below link. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu Kumaran. 



MK Muthu Kumaran Gnanavinayagam Syncfusion Team November 10, 2017 12:19 PM UTC

Hi Bharathi, 
 
We have checked with the attached image. You can achieve your requirement by setting padding for Frame and loading it inside a Grid. You can choose the desired BackgroundColor for Grid which will be applied as border color for the Frame when applying padding for all sides. For your assistance, we have attached the sample link with the screenshot below. 
 
 
Screenshot: 
 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu Kumaran. 



MK Muthu Kumaran Gnanavinayagam Syncfusion Team November 16, 2017 03:54 AM UTC

Hi Bharathi, 
 
Thanks for the update. 
 
Regards, 
G.Muthu Kumaran. 


Loader.
Up arrow icon