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

Command Binding From Xaml to ViewModel does not work (not debugable)

$
0
0

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


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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