How to select item from a SfListView, and pass it to an item detail view using MVVM

I have an SfListView with a list of items and ItemSelected set to an object in my VM. The app is a home growing app and my model is named Grow. I'd like to pass my selected item to my detail view to view the model data, but right now when I click an item in my list view there is no data shown in my detail view. I'm wondering what the best way to do it is, and what I'm doing wrong. My SelectedGrow property, that is bound to my ItemSelected property in Xaml is:

private Grow _selectedGrow;
public Grow SelectedGrow
{
get { return _selectedGrow; }

set
{
_selectedGrow = value;
OnPropertyChanged("SelectedGrow");
if (_selectedGrow != null)
{
App.Current.MainPage.Navigation.PushAsync(new GrowsDetailPage(new GrowsDetailPageViewModel(_selectedGrow)));
}
}
}




1 Reply

LN Lakshmi Natarajan Syncfusion Team December 30, 2021 09:06 AM UTC

Hi Jimmy, 
 
We suggest you bind the SelectedGrow property to the SfListView.SelectedItem property to achieve your requirement.  
 
Please refer to the following code snippets for more reference, 
<syncfusion:SfListView x:Name="listView"  
                    ItemsSource="{Binding ContactsInfo}" 
                    SelectedItem="{Binding SelectedGrow}"> 
 
You can refer to our user guidance document regarding programmatic selection, 
 
You can also refer to our online documentation regarding navigation on selection, 
KB links: 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon