我正在使用Xamarin.Android应用程序,我使用的是MvvmCross。我的代码中DecreaseCommand
无效:
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
没有解雇,这段代码可能出错?
答案 0 :(得分:1)
您在更新validateJson
媒体资源时忘记致电RaiseCanExecuteChanged
。
另外,您无需设置始终返回true的Quantity
:
CanExecute