Я работаю над приложением Xamarin.Android, и я использую MvvmCross. Вот в моем коде DecreaseCommand
не работает:CanExecute in 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
не стреляя, что может быть неправильно в этом коде?
Как вы связывании это? Работает ли команда «Увеличение»? –
Да Increasecommand works.when в CanExecuteDecreaseCommand() Я положил {return true}, тогда он работает fine.but, когда я положил {Quantity! = 0}, он не работает –