2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
SfListView allows you to navigate to another page when tapped on an element in the ListViewItem by adding the GestureRecognizers to that element in the ItemTemplate. In the below code example, added the TapGestureRecognizer to the Image and bound the Command to navigate the page when tapped on that image from ViewModel. XAML <ContentPage> <ContentPage.Content> <syncfusion:SfListView x:Name="listView" ItemSize="70" ItemsSource="{Binding contactsinfo}" SelectionMode="Single"> <syncfusion:SfListView.ItemTemplate> <DataTemplate > <ViewCell> <ViewCell.View> <Grid> <Image Source="Navigate.png"> <Image.GestureRecognizers> <TapGestureRecognizer Command="{Binding Path=BindingContext.TapCommand, Source = {x:Reference listView}}" CommandParameter="{Binding}" /> </Image.GestureRecognizers> </Image> </Grid> </ViewCell.View> </ViewCell> </DataTemplate> </syncfusion:SfListView.ItemTemplate> </syncfusion:SfListView> </ContentPage.Content> </ContentPage>
In the ViewModel, navigate to another page through INavigation interface when the tap command is invoked. C# public class ContactsViewModel : INotifyPropertyChanged { private Command<object> tapCommand; private INavigation navigation; public Command<object> TapCommand { get { return tapCommand; } set { tapCommand = value; } } public INavigation Navigation { get { return navigation; } set { navigation = value; } } public ContactsViewModel (INavigation _navigation) { navigation = _navigation; tapCommand = new Command<object>(OnTapped); } ///<summary> /// Navigating to a desired page on item tapped. ///</summary> private void OnTapped(object obj) { var newPage = new NewPage(); newPage.BindingContext = obj; Navigation.PushAsync(newPage); } }
The below screenshots show the main page and the navigated page.
Click here to download the sample. |
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
This Sample Project will not build. Multiple errors regarding embedded resources. Restoring and updating nuget packages does not correct any of the issues.
Hi Austin,
Sample project does not build due to long path name of the solution files. So we have modified the solution name and republished the documentation.
Regards,
G.Muthu Kumaran.
Line 31 is incorrect: Navigation.PushAsync(newPage);
It should be navigation.PushAsync(newPage); (lowercase 'n').
Disregard...