Hi.
I have a XAML form with button.
<StackLayout.BindingContext>
<viewModels:CartVM/>
</StackLayout.BindingContext>
<!-- other code -->
<ListViewItemsSource="{Binding Items}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
Button Text=" - "
Command="{Binding DecreaseQtyCommand}"
CommandParameter="{Binding}"
/>
<!-- other code -->
This is the ViewModel:
public class CartVM : BaseViewModel
{
public CartVM()
{
Items.CollectionChanged += ItemsHasBeenChanged;
}
public ObservableCollection<ShopCart> Items
{
get
{
return // list
}
}
public string Title {get;set;}
public string TotalAmount{get;set;}
public ICommand DecreaseQtyCommand
{
get
{
return new Command<ShopCart>((ShopCart shopCart) =>
{
shopCart.Qty -= 1;
OnPropertyChanged("Items");
});
}
}
The prolbem only with the Commands, the other Properties of CartVM work via Binding on the Xaml, like CartVM.Title, CartVM.TotalAmount