Is it okay to use ICommand in view-model

c#, mvvm, wpf

Solution

Any suggestions on this approach?

This still doesn't decouple you from `System.Windows.Input` as `RelayCommand` still must implement `ICommand`, even if it's indirectly implementing it.

Implementing `ICommand` within the ViewModel is one of those things that tends to be required in order to be pragmatic. Ideally, `ICommand` (or a similar interface) would have been implemented in a namespace that wasn't XAML specific. That being said, it is supported directly within the Portable Class Libraries, so it is not tied to a specific framework (WPF, Silverlight, Phone, etc) as much as XAML in general.

Problem

Most of the WPF mvvm applications, we are using `ICommand` in the view-model. But it is referring to `System.Windows.Input`. so the view-model is now tightly couple with `System.Windows.Input` namespace. according to my understanding view-model should be able to use in normal C# winform application or asp.net application. Normally we are using following code lines to the command with `RelayCommand` implementation. ``` private RelayCommand testCommand;// or private ICommand testCommand; public ICommand TestCommand { get { return testCommand ?? (testCommand = new RelayCommand(param => Test())); } } public void Test() { } ``` What i feel is we need to remove all the `ICommand` and use `RelayCommand` instead. So we can eliminate the `System.Windows` namespace from the view-model. so final code will looks like this, ``` private RelayCommand testCommand; public RelayCommand TestCommand { get { return testCommand ?? (testCommand = new RelayCommand(param => Test())); } } public void Test() { } ``` Any suggestions on this approach? or is there any way to eliminate the `System.Windows` namespace from the view-model?

Original source

Related problems