MVVM Routed and Relay Command

RoutedCommand is part of WPF, while RelayCommand was created by a WPF Disciple, Josh Smith ;). Seriously, though, RS Conley described some of the differences. The key difference is that RoutedCommand is an ICommand implementation that uses a RoutedEvent to route through the tree until a CommandBinding for the command is found, while RelayCommand does … Read more

Is Josh Smith’s implementation of the RelayCommand flawed?

I’ve found the answer in Josh’s comment on his “Understanding Routed Commands” article: […] you have to use the WeakEvent pattern in your CanExecuteChanged event. This is because visual elements will hook that event, and since the command object might never be garbage collected until the app shuts down, there is a very real potential … Read more

What is the actual task of CanExecuteChanged and CommandManager.RequerySuggested?

CanExecuteChanged notifies any command sources (like a Button or MenuItem) that are bound to that ICommand that the value returned by CanExecute has changed. Command sources care about this because they generally need to update their status accordingly (eg. a Button will disable itself if CanExecute() returns false). The CommandManager.RequerySuggested event is raised whenever the … Read more

MVVM Light RelayCommand Parameters

I believe this will work: _projmenuItem_Edit = new RelayCommand<object>((txt)=>ProjEditNode(txt)); — EDIT — You’ll need to define your RelayCommand with the type as well: e.g. public RelayCommand<string> myCommand { get; private set; } myCommand = new RelayCommand<string>((s) => Test(s)); private void Test(string s) { throw new NotImplementedException(); }

Why RelayCommand

Commands are used to separate the semantics and the object that invokes a command from the logic that executes the command i.e. it separates UI component from the logic that needs to be executed on command invocation. So, that you can test business logic separately using test cases and also your UI code is loosely … Read more