我正在使用Xamarin.Android應用程序,並且正在使用MvvmCross。在這裏,在我的代碼DecreaseCommand
不工作:可以在MvvmCross中執行
public class CartItemViewModel : MvxNotifyPropertyChanged
{
private int quantity = 0;
public CartItemViewModel()
{
IncreaseCommand = new MvxCommand(ExecuteIncreaseCommand, CanExecuteIncreaseCommand);
DecreaseCommand = new MvxCommand(ExecuteDecreaseCommand, CanExecuteDecreaseCommand);
Delete = new MvxCommand (() => {Quantity++;});
}
public int Quantity
{
get { return quantity; }
set
{
quantity = value;
RaisePropertyChanged("Quantity");
RaisePropertyChanged("SubTotal");
}
}
public ICommand IncreaseCommand { get; set; }
public ICommand DecreaseCommand { get; set; }
public ICommand Delete { get; set; }
private void ExecuteIncreaseCommand()
{
Quantity++;
}
private bool CanExecuteIncreaseCommand()
{
return true;
}
private void ExecuteDecreaseCommand()
{
Quantity--;
}
private bool CanExecuteDecreaseCommand()
{
return Quantity > 0;
}
}
我懷疑CanExecuteDecreaseCommand
不點火,這可能是錯誤的代碼?
你是如何結合的? Doe增加命令工作嗎? –
是增加命令work.when在CanExecuteDecreaseCommand()我把{返回true}然後它工作正常。但是當我把{Quantity!= 0}它不起作用 –