jeudi 12 novembre 2020

Checkbox from ComboBoxItem is binded to Boolean in Class. How to get every Boolean from every single Item?

Sorry for my lacking of English and take in mind I just startet with WPF, so it might not even be the prettiest way to do this.

I tried to remove every Item where the Checkbox is Checked but I have Problems to point toward the Checkbox. So I tried to point toward a Boolean within a Class. But there are also Problems. Then I surrendered and came here.

Any Help is appreciated.

My Button who should delete a certain Item, with a checked checkbox, from a list looks like this.

private void DeleteComboBoxItem_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < ComboBoxName.Items.Count; i++)
            {
                if (ComboBoxName.Item.Contains((CheckBox).Equals(True))) <--- Have Problems here.
                {
                    List.RemoveAt(i);
                }
            }
        }

Only the Name of the Cat is within the List - I have a formula where I can add cat names.

I have a ComboBox with the following template:

<ComboBox x:Name="ComboBoxName">
     <ComboBox.ItemTemplate>
           <DataTemplate>
                <Grid HorizontalAlignment="Stretch">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="Auto"/>
                         <ColumnDefinition Width="*"/>
                     </Grid.ColumnDefinitions>
                     <CheckBox Grid.Column="0" IsChecked="{Binding b_CheckBox}" VerticalContentAlignment="Center"/>
                     <TextBlock Grid.Column="1" Text="{Binding tb_Name}" />
                </Grid>
           </DataTemplate>
     </ComboBox.ItemTemplate>
</ComboBox>

And a class that looks something like that.

public class Cat 
{
public bool b_Checkbox {get; set;}
public string tb_Name {get; set;}
}

Hope you can Help me.




Aucun commentaire:

Enregistrer un commentaire