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

Implementing “close window” command with MVVM

I personally use a very simple approach: for every ViewModel that is related to a closeable View, I created a base ViewModel like this following example: public abstract class CloseableViewModel { public event EventHandler ClosingRequest; protected void OnClosingRequest() { if (this.ClosingRequest != null) { this.ClosingRequest(this, EventArgs.Empty); } } } Then in your ViewModel that inherits … 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

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

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

tech