This project has moved and is read-only. For the latest updates, please go here.

cancellable icommand desired for Universal projects

Aug 11, 2014 at 6:49 AM
Your MSDN article covered a bindable ICommand implementation that could be cancelled. I wanted to use it in a Universal project but it wouldn't compile because the code referenced the CommandManager. When I replaced that code with the standard event handler code you see in most ICommand/event implementations (just define the event without that strange add and remove syntax) it compiled fine but the CanExecute didn't seem to work anymore. It was always disabled. I'd like to understand why you need to do that CommandManager thing in the event definition, and whether there is a way to make it work in a Universal project.
Aug 11, 2014 at 1:45 PM
ICommand.CanExecuteChanged is weird; it is defined in the interface as looking like a normal event, but it is actually an error to implement it as such. A standard event definition will cause memory leaks on WPF.

If you do define your own event (or weak event manager), then you'll need to raise the CanExecuteChanged event yourself. CommandManager will always raise its event whenever the user interacts with the UI.