I have a very simple button binded to a command
<Button Content="Add" Margin="10,10,10,0" Command="{Binding SaveCommand}" ></Button>
My command code
public ICommand SaveCommand
{
get;
internal set;
}
private bool CanExecuteSaveCommand()
{
return DateTime.Now.Second % 2 == 0;
}
private void CreateSaveCommand()
{
SaveCommand = new DelegateCommand(param => this.SaveExecute(), param => CanExecuteSaveCommand());
}
public void SaveExecute()
{
PharmacyItem newItem = new PharmacyItem();
newItem.Name = ItemToAdd.Name;
newItem.IsleNumber = ItemToAdd.IsleNumber;
newItem.ExpDate = ItemToAdd.ExpDate;
PI.Add(newItem);
}
The code effectively blocks the command from running based on CanExecuteSaveCommand but the button is never disabled, is there a way to achieve this?