In a user control I have this:
<ToggleButton x:Name="toggleButton" Style="{StaticResource PaneToggleButton}"
Content="{Binding MyChromaticNotes.Root.Note}">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Checked">
<Core:InvokeCommandAction
Command="{Binding AddSelectedCommand}" />
</Core:EventTriggerBehavior>
<Core:EventTriggerBehavior EventName="UnChecked">
<Core:InvokeCommandAction
Command="{Binding RemoveSelectedCommand}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</ToggleButton>
The two commands are binding to my view-model's static properties of type 'DelegateCommand' which implements ICommand. In the view model constructor, I have this:
#region Add Selected
AddSelectedCommand = new DelegateCommand(
() => { SelectedTones.Add(MyChromaticNotes.Root.Note); },
() => { return true; }
);
#endregion
#region Remove Selected
RemoveSelectedCommand = new DelegateCommand(
() => { SelectedTones.Remove(MyChromaticNotes.Root.Note); },
() => { return SelectedTones.Contains(MyChromaticNotes.Root.Note); }
);
#endregion
If I try to run it I get "Cannot add instance of 'EventTriggerBehavior' to collection of type BehaviorCollection" on the Output Window, but if I remove the second 'EventTriggerBehavior' from the XAML and the corresponding RemoveSelectedCommand DelegateCommand from the view model It runs and I can Add to SelectedTones (of type ObservableCollection).
Question: Why is the second EventTriggerBehavior not working, how to fix?
The event name is Unchecked
not UnChecked
.
Casing matters.