Home:ALL Converter>Is the common implementation of RelayCommand violating the MVVM pattern?

Is the common implementation of RelayCommand violating the MVVM pattern?

Ask Time:2016-03-10T16:04:02         Author:Tim Pohlmann

Json Formatter

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?

Author:Tim Pohlmann,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35910781/is-the-common-implementation-of-relaycommand-violating-the-mvvm-pattern
yy