var cmd = new DelegateCommand<double>(...)?

Topics: Prism v4 - Silverlight 4
Sep 22, 2010 at 12:12 AM

Can you tell me if any thought has been given to allowing the creation of delegate commands where the command's parameter type is a non-reference type. I'm thinking of the case of where maybe you have a Map object and you want to zoom to a particular scale but the scale is a double. You could create an class to hold the scale parameter and pass that to the command but it would be more convenient to declare a delegate command with the parameter of type double. This currently does not appear to be possible because the T parameter has a class constraint.

Does that make sense or am I missing something?

Kevin Rintoul
Latitude Geographics

Sep 22, 2010 at 1:06 PM

Hi Kevin,

Thanks for your feedback, since it is really valuable. I will copy this as a work-item, so the product team will be notified. Additionally, it allows that other users could vote for this.

As you mentioned this implementation of Delegate command has a class constrain, so It does not accept double/Double as a value type or struct. The workaround within sight is to create another implementation of the DelegateCommand without this constraint or create your own Command.

Fernando Antivero
http://blogs.southworks.net/fantivero

Sep 22, 2010 at 1:07 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 22, 2010 at 4:50 PM

We did look into this.  However, there is a problem with using value types in this instance if the class constraint is removed.  The ICommand interface (implemented by DelegateCommand) has two methods that both take objects, which by itself would not be an issue.  However, when you add binding from XAML into the mix with value types, there will often be null values for the value types, which for double or int is an issue.  We did look into constraining the DelegateCommand to nullable value types, but there is no such constraint to ensure that there are no issues.

There has been some work done in the DelegateCommand which you could leverage and use the DelegateCommandBase to create your own.  As a fallback, you can also do a DelegateCommand<object>, cast yourself where necessary, and handle the null values as appropriate for your app.

 

Oct 12, 2010 at 2:54 PM

Hi Kevin,

In the Drop 9 of Prism the product team has updated the DelegateCommand<T> class to support value types by using a Nullable<T>. I think that you can find interesting the comments from the product team in the work-item.

Thanks again for your feedback, since it was really useful.

Fernando Antivero
http://blogs.southworks.net/fantivero