CanExecute CommandParameter CurrentItem

Dec 9, 2009 at 3:36 AM

I am having an issue with passing the currentItem to the CanExecute.

Imagine a Customers grid, that has a child grid of Orders. If the order has shipped it can't be edited, but otherwise it can. Except on Tuesdays after 3 pm :P (just a joke there).

So my template column has a Edit button that ties to a Command = "{Binding EditCommand}" and a CommandParameter="{Binding}".  (Actually, the CommandParameter is BEFORE the Command statement in the XAML).

I implement the ICommand (Technically a DelegateCommand<T> from Prism, but I believe it is irrelevant to this discussion) in the ViewModel. The CanEditExecute(object e), e is always null. I need this to pass in the CurrentItem so that I can see if the status is Shipped. 

Hope this is clear enough. I've looked through this forum and googled the heck out of it. Found some references to using the CommandMangaer.InvalidateSomethingOrOther() and tried that, but to no avail.

Thanks !



Feb 11, 2010 at 8:23 AM

I'm seeing the same problem. I set CommandParameter="{Binding}" (or "{Binding Foo}") in my MenuItem, and the parameter passed to the CanExecute method of my DelegateCommand is always null.

If I hard code my CanExecute to return true so I can make it call the Execute command, the parameter is passed through just fine. So the problem appears to be limited ot the CanExecute method when it requires a parameter.

Is there a fix for this?