2016-06-29 2 views
0

Dans un contrôle utilisateur J'ai ceci:mal à ajouter secondes EventTriggerBehavior pour contrôler - UWP

 <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> 

Les deux commandes sont obligatoires à mes propriétés statiques de vue-modèle de type « DelegateCommand » qui met en œuvre ICommand. Dans le constructeur de modèle de vue, j'ai ceci:

 #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 

Si je tente de l'exécuter je reçois « Impossible d'ajouter par exemple de « EventTriggerBehavior » à la collecte de type BehaviorCollection » dans la fenêtre de sortie, mais si je retire la second 'EventTriggerBehavior' à partir du XAML et la DelegateCommand RemoveSelectedCommand correspondante du modèle de vue Il s'exécute et je peux ajouter à SelectedTones (de type ObservableCollection). Question: Pourquoi le second EventTriggerBehavior ne fonctionne pas, comment résoudre ce problème?

Répondre

0

Le nom de l'événement est Unchecked pas UnChecked.

Le boîtier est important.

+0

Bien sûr, la faute de frappe – olhodolago