A very common implementation of RelayCommand
seems to include the following lines:
public event EventHandler CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
}
remove
{
CommandManager.RequerySuggested -= value;
}
}
This seems very flawed to me, because CommandManager
is a WPF component and usually my commands are located in a viewmodel class. Since the viewmodel is not supposed to know the view and should work with different frameworks and such, this seems very strange to me. For example this implementation will not even be possible if you separate your viewmodel in an extra project, that doesn't know the WPF namespace (e.g. PCL).
Is this implementation violating the MVVM pattern?
Or do you maybe place the RelayCommand
in your view somehow?
If this is indeed flawed, is there a best practice implementation that solves this issue?