ICommand.CanExecute being passed null even though CommandParameter is set...
- by chaiguy
I have a tricky problem where I am binding a ContextMenu to a set of ICommand-derived objects, and setting the Command and CommandParameter properties on each MenuItem via a style:
<ContextMenu
ItemsSource="{Binding Source={x:Static OrangeNote:Note.MultiCommands}}">
<ContextMenu.Resources>
<Style
TargetType="MenuItem">
<Setter
Property="Header"
Value="{Binding Path=Title}" />
<Setter
Property="Command"
Value="{Binding}" />
<Setter
Property="CommandParameter"
Value="{Binding Source={x:Static OrangeNote:App.Screen}, Path=SelectedNotes}" />
...
However, while ICommand.Execute( object ) gets passed the set of selected notes as it should, ICommand.CanExecute( object ) (which is called when the menu is created) is getting passed null. I've checked and the selected notes collection is properly instantiated before the call is made (in fact it's assigned a value in its declaration, so it is never null). I can't figure out why CanEvaluate is getting passed null.