I have an application, which uses RelayCommand
s in an MVVM architecture.
It seems that at some point in time the CanExecute
methods no longer get properly re-evaluated. (maybe installing latest updates for VS2013 caused this?).
The code below seems as basic as it can get, I really hope somebody can help me out.
Declaration of relay command:
public RelayCommand BrowseTorrentSiteCommand { get; private set; }
Instantiation of relay command:
BrowseTorrentSiteCommand = new RelayCommand(BrowseTorrentSiteOnExecuted, BrowseTorrentSiteOnCanExecute);
Implementation of CanExecute:
private bool BrowseTorrentSiteOnCanExecute()
{
return _mainViewViewModel.SelectedTvShow != null;
}
Implementation of SelectedTvShow property in VM:
public TvShowViewModel SelectedTvShow
{
get { return _selectedTvShow; }
set
{
_selectedTvShow = value;
OnPropertyChanged();
}
}
Updating the selected tv show:
public void TvShowsSelectionChanged()
{
Episodes.Clear();
var queryEpsidesForSelection = new QueryEpsidesForSelection(TvShows);
foreach (var episode in queryEpsidesForSelection.QueryEpisodes())
{
Episodes.Add(episode);
}
SelectedTvShow = queryEpsidesForSelection.SelectedTvShow;
MainCommandsViewModel.DownloadNewestEpisodesCommand.RaiseCanExecuteChanged();
//MainCommandsViewModel.BrowseTorrentSiteCommand.RaiseCanExecuteChanged();
}
I intentionally commented the last line where I force the RaiseCanExecuteChanged
being called, I NEVER had to use that before. Obviously this solves the problem, but I use a lot of RelayCommands and all of them seem to suffer from the same problem: their CanExecute
methods are no longer re-evaluated automatically.
What can be the cause that the CanExecute
method no longer gets fired ?