problem with CommandParameter in SimpleCommand

Sep 21, 2011 at 10:44 AM


i have implemented the Simple Command like it is described in the article at codeproject, but I have a problem with the commandparameter.

this is my command implementation:

        public SimpleCommand<objectEventToCommandArgs> CmdPreviewReport
            get { return new SimpleCommand<objectEventToCommandArgs>(CanExecutePreviewReport, ExecutePreviewReport); }

        public void ExecutePreviewReport(EventToCommandArgs args)
            Report report = args.CommandParameter as Report;

 i call it from code:
                    openReportMenuItem.Command = myVM.NewUITemplateCommand;
                    openReportMenuItem.CommandParameter = navTreeItem.BusinessObject;

I get an invalid cast exception form the cinch codebase at
        public void Execute(object parameter)
            Execute((T2)parameter);//parameter is not of type EventToCommandArgs!!
Am I using this wrongly or is this a bug?
Sep 21, 2011 at 11:09 AM


you are using it wrong.

The seconde generic type have to be the type of the command parameter, so in your case the the type from the object in



EventToCommandArgs is only used as a wrapper by the EventToCommandTrigger

<i:EventTrigger EventName="MouseDoubleClick">
                        Command="{Binding MouseDoubleClickCommand}" 
                        CommandParameter="{Binding SelectedItem, ElementName=dgTickets}"/>
Sep 22, 2011 at 12:57 PM

I understand. Thanks a lot for your quick anwer!

Sep 26, 2011 at 8:58 AM

As Helmut already stated, you were using it wrong

Sep 26, 2011 at 8:59 AM

Thanks for grabbing that one Helmut