RelayCommand is an implementation of the .NET ICommand interface made and described by WPF expert Josh Smith.
Questions tagged [relaycommand]
289 questions
78
votes
4 answers
MVVM Routed and Relay Command
What is the Difference between the RoutedCommand and RelayCommand ?
When to use RoutedCommand and when to use RelayCommand in MVVM pattern ?

user72799
- 781
- 1
- 6
- 3
61
votes
2 answers
Why RelayCommand
I've been programming a lot in WPF lately but my View and ViewModel are not separate at this point. Well, it's partially. All my bindings concerned to text in text boxes, content for labels, lists in datagrids, ... are done by regular properties…

Krowi
- 1,565
- 3
- 20
- 40
45
votes
3 answers
MVVM Light RelayCommand Parameters
I'm having an issue with passing a parameter to a relaycommand using the GalaSoft MVVM Light framework. I know that mvvm light's implementation of relaycommand doesn't use lambda parameters, so I did some research and found a way that people worked…

Saggio
- 2,212
- 6
- 33
- 50
45
votes
5 answers
Is Josh Smith's implementation of the RelayCommand flawed?
Consider the reference Josh Smith' article WPF Apps With The Model-View-ViewModel Design Pattern, specifically the example implementation of a RelayCommand (In Figure 3). (No need to read through the entire article for this question.)
In general,…

Greg D
- 43,259
- 14
- 84
- 117
44
votes
13 answers
Implementing "close window" command with MVVM
So my first attempt did everything out of the code behind, and now I'm trying to refactor my code to use the MVVM pattern, following the guidance of the MVVM in the box information.
I've created a viewmodel class to match my view class, and I'm…

mcalex
- 6,628
- 5
- 50
- 80
41
votes
2 answers
How can I use the RelayCommand in wpf?
How can I use the RelayCommand in wpf?

Sauron
- 16,668
- 41
- 122
- 174
39
votes
3 answers
What is the actual task of CanExecuteChanged and CommandManager.RequerySuggested?
I got the following code from Josh Smith's MVVM tutorial.
Can anyone provide a quick explanation of what this code actually does?
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove {…

Aryan SuryaWansi
- 2,691
- 10
- 31
- 33
19
votes
6 answers
Simplifying RelayCommand/DelegateCommand in WPF MVVM ViewModels
If you're doing MVVM and using commands, you'll often see ICommand properties on the ViewModel that are backed by private RelayCommand or DelegateCommand fields, like this example from the original MVVM article on MSDN:
RelayCommand…

Ben Schoepke
- 789
- 2
- 7
- 17
18
votes
4 answers
is asynchronous version of relaycommand required in order to run async methods correctly
I have the following code defined in a viewmodel. I think that the SaveAsync of type Func is getting converted to Action since RelayCommand takes an Action not a Func but I'm not clear on the implications of that.
1) Does RelayCommand…

Coding Dude
- 617
- 1
- 6
- 16
16
votes
3 answers
Passing event args and sender to the RelayCommand
How do you get event sender when using RelayCommand?

incognito
- 2,243
- 3
- 14
- 16
15
votes
5 answers
The name "CommandManager" does not exist in the current context (Visual Studio 2015)
Trying to use the RelayCommand class below I received the error message: "The name "CommandManager" does not exist in the current context". According to this post Class library does not recognize CommandManager class I tried to solve the problem by…

user3350279
- 2,589
- 2
- 13
- 8
12
votes
2 answers
RelayCommand stops working after a while
I am facing some problems using GalaSoft's RelayCommand.
I have a NextCommand property that works, but only several times.
Afterwards, it stops working completely.
You can try this out with the sample…

jayars
- 1,347
- 3
- 13
- 25
11
votes
3 answers
CanExecute on RelayCommand not working
I'm writing a WPF 4 app (with VS2010 RC) using MVVM Light V3 alpha 3 and am running into some weird behaviour here...
I have a command that opens a Window, and that Window creates the ViewModel and so on - nothing weird there.
In that Window I have…

Jesus Rodriguez
- 11,918
- 9
- 64
- 88
10
votes
1 answer
Programatic re-evaluation of MVVM command's "can execute" state
I'm writing a WPF application using the MVVM pattern, based on the following article: WPF Apps With The Model-View-ViewModel Design Pattern
I have two buttons on my View with the buttons' "Command" property bound (with data binding) to a given…

dzs
- 729
- 6
- 11
10
votes
3 answers
How do you bind a command to a MenuItem (WPF)?
Here is my code from the View.xaml.cs:
private RelayCommand _closeCommand;
public ICommand CloseCommand
{
get
{
if (_closeCommand == null)
{
_closeCommand = new RelayCommand(param => this.OnClose());
}
…

Jackson Dean Goodwin
- 617
- 3
- 11
- 20