I recently started using WPF and the MVVM framework, one thing that I have wanted to do is to have a type safe implementation of ICommand so I do not have to cast all the command paramaters.
Does anyone know of a way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not using that syntax, as you probably found:
Your best bet is to encapsulate theFunc<E,bool>semantics in an interface, like:and then use this interface in the class definition. Although, I am wondering what you’re looking to accomplish as there may be another approach to your problem.
Per the comment that @Alex is looking for a strongly typed
ICommandimplementation:Used like so:
XAML:
I would recommend using Microsoft’s DelegateCommand or RelayCommand, or any other implementation of either of these.