Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

ListView item selected not working in MvvM

$
0
0

Hi Everyone ,
I am new to xamarin and i am developing an app.
I am working on the listview item tapped navigation in mvvm where when user taps on the list item it will navigate to the detail page of the tapped item.
Following is my code for design

      <ListView HasUnevenRows="True" x:Name="list" 
                SelectedItem="{Binding MySelectedItem}" ItemsSource="{Binding UserTrailList}" >

               <ListView.ItemTemplate >
              <DataTemplate> 
             <ViewCell>
                  <ViewCell.ContextActions>
                    // my detail desing here
                  </ViewCell.ContextActions>

      </ListView>

Following is ViewModel code

     private readonly IWebService _webService;
      private readonly IMvxNavigationService _navigationService;
       public UserTrailModel _ItemSelected;
      private OfflineService _offlineService;
     private ObservableCollection<UserTrailModel> _userTrailList;
     string trailId="";


    private UserTrailModel _mySelectedItem { get; set; }

      public UserTrailModel MySelectedItem
     {

        get { return _ItemSelected; }
        set
        {

            if (_mySelectedItem != null)
            {
                _navigationService.Navigate<TrackingTourDetailsViewModel>();
            }
        }
    }



    public OfflineService OfflineService
    {
        get => _offlineService ?? (_offlineService = new OfflineService(FormsApp.PeakRLocalDBContext.SQLiteDBConnection));
        set
        {
            _offlineService = value;
            RaisePropertyChanged(() => OfflineService);
        }
    }

    public ObservableCollection<UserTrailModel> UserTrailList
    {
        get => _userTrailList ?? (_userTrailList = new ObservableCollection<UserTrailModel>());
        set
        {
            _userTrailList = value;
            RaisePropertyChanged(() => UserTrailList);


        }
    }

Please help me find the solution or is there anything wrong in may code .


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>