listView.Loaded += ListView_Loaded;
…
private void ListView_Loaded(object sender, ListViewLoadedEventArgs e)
{
(listView.LayoutManager as LinearLayout).ScrollToRowIndex(ViewModel.contactsinfo.Count);
}
|
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
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;
} |
<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> |