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

CanExecute CommandParameter Specified cast is not valid

Nov 15, 2013 at 7:18 PM
Edited Nov 15, 2013 at 8:09 PM
I have a RelayCommand which accepts a command parameter of type int. If I leave off the CanExecute everything works fine. If I add a trivial CanExecute, I get the error: Specified cast is not valid.

Am I using this incorrectly?
IncrementDateCommand = new RelayCommand<int>(amount => Date = Date.AddDays(amount), amount => return true);
<Button Content="&gt;" Command="{Binding IncrementDateCommand}" CommandParameter="1" />
   at GalaSoft.MvvmLight.Command.RelayCommand`1.CanExecute(Object parameter) in g:\GalaSoft\mydotnet\MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight (NET35)\Command\RelayCommandGeneric.cs:line 186
   at System.Windows.Controls.Primitives.ButtonBase.UpdateCanExecute()
   at System.Windows.Controls.Primitives.ButtonBase.OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

This works.
<Button Content="&gt;" Command="{Binding IncrementDateCommand}">
I just find it interesting that in the original the cast to an int works for execute, but not canExecute.