vendredi 9 juin 2023

c# WPF MVVM: Checkbox doesnt Fire Event "Checked" or "Unchecked"

im new to the MVVM pattern and i got a problem with checkboxes inside of a listview.. When i put a checkbox as item into a listview the events "checked" and "unchecked" does not fire. But when i add a checkbox outside of the listview e.g. in a stackpanel, the events fire.

Could anybody explain the problem?

Thank you in advance.

This is my used code:

xmlns:behav="http://schemas.microsoft.com/xaml/behaviors"
<Border Grid.Row="1" Grid.Column="0" BorderThickness="2" Grid.RowSpan="3" BorderBrush="{StaticResource MainMenuColor}">
  <ListBox ItemsSource="{Binding ListBoxItems}" Background="Transparent" Foreground="{StaticResource MainMenuColor}">
    <ListBox.ItemTemplate>
      <DataTemplate>
        <CheckBox FontFamily="{StaticResource FontProtokoll}" IsChecked="{Binding IsChecked}" Content="{Binding Path=Text}" Foreground="{StaticResource MainMenuColor}">
          <behav:Interaction.Triggers>
            <behav:EventTrigger EventName="Checked">
              <behav:InvokeCommandAction Command="{Binding CheckedOrUncheckedCommand}"/>
            </behav:EventTrigger>
          </behav:Interaction.Triggers>
        </CheckBox>
      </DataTemplate>
    </ListBox.ItemTemplate>
  </ListBox>
</Border>




Aucun commentaire:

Enregistrer un commentaire