First, I'm not sure if you can pass Enum directly from XAML to Silverlight. In any case, there is a small problem in the Prism. See The command that comes before the CommandParameter, what happens when the command receives a lot inside. Prism calls UpdateEnabledState (), which internally calls CanExecute (the object parameter) on your Kommente, passing it a CommandParameter (which has not yet been set)
here is the base code from DelegateCommand.cs in Prism
bool ICommand.CanExecute(object parameter) { return CanExecute((T)parameter); }
since the parameter is "null" at this point, the throw throws an exception. Here's how I got around this issue.
Your listing.
namespace CodeExpert.Book.Helpers { public enum BookDirection { Previous = -1, NotSet = 0, Next = 1, } }
here is my delegate declaration, pay attention to using an object ... instead of Enum itself. I also expose properties from ViewModel which will expose 2 different directions.
public DelegateCommand<object> PreviousNextCommand { get; set; } public BookDirection Previous { get { return BookDirection.Previous; }} public BookDirection Next { get { return BookDirection.Next; }}
now in your OnPreviousNextCommandExecute make sure you get the object and return it to the corresponding enumeration
private void OnPreviousNextCommandExecute(object parameter) { BookDirection direction = (BookDirection)parameter;
and in XAML, they are directly related to the public properties of BookDirection.
<Button Content="Next" Commands:Click.Command="{Binding PreviousNextCommand}" Commands:Click.CommandParameter="{Binding Next}" /> <Button Content="Previous" Commands:Click.Command="{Binding PreviousNextCommand}" Commands:Click.CommandParameter="{Binding Previous}" />
I'm not sure about your binding situation, because in my case I set my DataContext directly in the ViewModel. But that should work for you.
Sorry for my poor English and eloquence, hope this puts you on the right track.