DelegateCommand<T>.ConvertParameter fails with ICommand and no CommandParameter

Sep 19, 2011 at 9:27 PM

If you specify a button in your XAML, and bind a Command to it like this;

<Button Content="Cancel" Command="{Binding Path=DashboardEditCancelCommand}">

the DelegateCommand<T>.ConvertParameter method will fail because the "parameter" value is null.  It seems that it would be a legitimate case to have a button that just calls an ICommand method without a parameter.  Especially if it is just a Cancel button or something similar.  As a work-around I added CommandParameter="0" to the declaration of my button.  Then I just ignore the parameter value.




Sep 21, 2011 at 2:05 PM

Hi Marty,

There is a non-generic version of DelegateCommand that you need to use, which takes a parameterless method.  Just remove the parameter from your ViewModel method and you should be OK.  That said, I lean toward using a Blend event trigger instead of a command when there are no parameters involved.  For more info, see my blog post: