problem with CommandParameter in SimpleCommand

Sep 21, 2011 at 11:44 AM

Hello,

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 12:09 PM

Hello,

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

navTreeItem.BusinessObject;

 

EventToCommandArgs is only used as a wrapper by the EventToCommandTrigger

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

I understand. Thanks a lot for your quick anwer!

Sep 26, 2011 at 9:58 AM

As Helmut already stated, you were using it wrong

Sep 26, 2011 at 9:59 AM

Thanks for grabbing that one Helmut