Archive for June, 2007
My understanding of the .NET design philosophy is that if you handle an event with an empty handler, it should behave essentially as if you had not handled the event at all. This may not be the case, but it seems to be in most things… if you handle the Close window event and don’t do anything, the window still closes.
However, with WPF, this isn’t always the case. For example, the following line of code adds a pair of new handlers to a defined command:
new ExecutedRoutedEventHandler( ToggleCommand ),
new CanExecuteRoutedEventHandler( CanToggleCommand )));
If you implement an empty handler for ToggleCommand, it gets called and life goes on.
If you implement an empty handler for CanToggleCommand, everything grinds to a halt because the COMMAND IS NO LONGER CALLED.
Why is this? Why do I have have to explicitly set args.CanExecute = true? Why does an empty handler change the behavior?