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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Raising Property changed on SelectedItem doesnt fire SelectionChanging or SelectionChanged

Thread ID:





130805 Jun 4,2017 04:52 PM UTC Jun 5,2017 08:54 AM UTC Xamarin.Forms 1
Tags: SfListView
Asked On June 4, 2017 04:52 PM UTC

I would like to change selectedItem only 1 way from viewModel to View and I expect SelectionChanging or/and SelectionChanged events are fired. 

  <sfListView:SfListView x:Name="list"   ItemsSource="{Binding Items}" SelectionMode="Single"  SelectionGesture="Tap"
             ItemSpacing="2" AllowSwiping="False"   SelectionChanging="list_SelectionChanging"  SelectionBackgroundColor="Yellow"  Orientation="Horizontal"
                               SelectedItem="{Binding SelectedItem, Mode=OneWay}" >

When I raise    RaisePropertyChanged("SelectedItem"); in ViewModel, it works fine, I can see selectedItem is changed but I want to scroll to the selectedItem, Thats why I tried SelectionChanging or SelectionChanged events but not luck. they arent fired. they are fired only when I tap on an item. What is the reason for that? How can I achieve my purpose? I need to scroll to selecteditem but selecteditem should be set in the ViewModel

      private void list_SelectionChanging(object sender, Syncfusion.ListView.XForms.ItemSelectionChangingEventArgs e)
                (list.LayoutManager as Syncfusion.ListView.XForms.LinearLayout).ScrollToRowIndex(vm.SelectedItem.DisplayOrder);
            catch (Exception ex)

Dinesh Babu Yadav [Syncfusion]
Replied On June 5, 2017 08:54 AM UTC

Hi Emil, 
Sorry for the inconvenience caused. 
We would like to let you know that the SelectionChanging and SelectionChanged events are triggered only when the selection is performed by gesture action instead of programmatic selection. However, the reported requirement “Need to scroll to selected item in SfListView” can achieved by sample level. While initializing the SfListView, you can scroll to SelectedItem through Loaded event in which you can get the selected item’s index from the DisplayItems.Indexof() method and scroll to that item by using ScrollToRowIndex method as like below code snippet. 
Code Example[C#]: 
private void ListView_Loaded(object sender, Syncfusion.ListView.XForms.ListViewLoadedEventArgs e) 
 (listView.LayoutManager as LinearLayout).ScrollToRowIndex(listView.DataSource.DisplayItems.IndexOf(ViewModel.SelectedItem));   
Also, if you are changing the SelectedItem (ViewModel property) through button click event or any gesture action at runtime, you can use the ScrollToRowIndex method in the clicked or gesture event as same like above code snippet. 
For your reference, we have attached the sample and you can download it from the below link. 
Please let us know if you require further assistance. 
Dinesh Babu Yadav 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon