I have a static delegate command. I'm passing a bool to the constructor. However, it is throwing a runtime exception.
public static class myViewModel
{
public static ICommand myCommand {get; private set;}
static myViewModel
{
//If I change the bool to Object, or to Collection type, no exception assuming that I change myMethod parameter as well to the same type.
myCommand = new DelegateCommand<bool>(myMethod);
}
private static void myMethod (bool myBoolean)
{
//To Do
}
}
Always, always, always tell us what type of exception you got, and what the exception message was. They have many, many different exceptions because every one is thrown for a different reason.
But in this case, it looks like the problem is that bool
is a value type, and the code that executes the command is passing it a null
for a parameter. But you can't cast null
to a value type, and trying to do so will cause a runtime exception:
object o = null;
// This will compile, but blow up at runtime.
bool b = (bool)o;