I'm binding a control to a DelegateCommand and the CanExecute portion of it is not working properly. I am using the Prism libraries. Can anyone tell me why?
Command declaration and instantiation:
public PlayerManagementViewModel(DatabaseManager dbManager)
{
_dbManager = dbManager;
this.ResetUpToDateStatusCommand = new DelegateCommand(() => this.ResetXpUpToDateStatus());
this.DeletePlayerCommand = new DelegateCommand(() => this.DeleteSelectedPlayer(), () => SelectedPlayer != null);
this.RefreshPlayers();
}
public ICommand DeletePlayerCommand { get; private set; }
SelectedPlayer definition:
public Player SelectedPlayer
{
get { return _selectedPlayer; }
set
{
SetProperty(ref this._selectedPlayer, value);
this.OnPropertyChanged(() => this.FormattedPlayerStatus);
}
}
The weird thing is that if you look at the line above the DeletePlayerCommand
instantiation, that line works just fine. I don't get any CanExecute
behavior out of it, but at least it works. As is, the DeletePlayerCommand
command never fires off, even with a breakpoint, unless I remove the CanExecute portion of the constructor entirely.
Can anyone please explain to me why this is or what I'm doing wrong?