


(The view model class is assigned to the BindingContext in the view's constructor.)ĭo you have a more complete sample of code? said: In my view model, the ObservableCollection collection is named Projects. I adapted and used this code in my project, but I receive an exception when I launch the containing view. Public ObservableCollection Users => īut I believe that this approach is not the one that should be used in MVVM, since I have some logic in the Model. Public MainPageViewModel(INavigationService navigationService, IPageDialogService dialogService) Public DelegateCommand DeleteCommand => _deleteCommand ? (_deleteCommand = new DelegateCommand(DeleteUser)) Public ObservableCollection Users => _users

Here's my ListView: Īnd the corresponding ViewModel (I removed some code to save space): public class MainPageViewModel : BindableBase, INavigatedAware I use Prism with Unity for MVVM, if this is of any importance. Binding the SelectedItem of the ListView does not help, since a long tap on Android or a swipe on iOS don't select the item. Hi, I am new to Xamarin, Forms and MVVM, so this might sound a little dumb, but what is the proper way to delete an item from a ListView? I tried to do it with a ContextAction, but I can't figure a way to know in my ViewModel which item to delete from the ObservableCollection.
