我在哪里运行我的CreateBestPriceListCanExecute
方法以便CanExecute
在下面的代码片段中更新我的?
class BestPriceViewModel : ViewModelBase
{
ObservableCollection<BestPriceModel> bestPriceList = new ObservableCollection<BestPriceModel>();
public ICommand createBestPriceListCommand;
private bool canExecute = true;
public BestPriceViewModel()
{
createBestPriceListCommand = new RelayCommand(CreateBestPriceList, param => this.CanExecute);
btnLoadItemList = "Import";
} public ObservableCollection<BestPriceModel> BestPriceList
{
get { return this.bestPriceList; }
set
{
if (this.bestPriceList != value)
{
this.bestPriceList = value;
this.OnPropertyChanged("BestPriceList");
}
}
}
public bool CanExecute
{
get
{
return this.canExecute;
}
set
{
if (this.canExecute == value)
{
return;
}
this.canExecute = value;
}
}
public ICommand CreateBestPriceListCommand
{
get
{
return createBestPriceListCommand;
}
set
{
createBestPriceListCommand = value;
}
}
public bool CreateBestPriceListCanExecute()
{
bool DbCheck = DataBaseAccess.connection.State != ConnectionState.Open &&
DataBaseAccess.connection.State != ConnectionState.Fetching &&
DataBaseAccess.connection.State != ConnectionState.Executing ? true : false;
return DbCheck;
}
}
我的CreateBestPrice
方法是使用数据库,它有一个在后台运行的自动数据库更新程序,有时会上传信息。那些时候我需要我CanExecute
是假的,还有其他方法吗?