So I got in WPF an ListBox where I got an Button in my ListBoxItem through an DataTemplate. Im adding that Button Like this to my Item:
<ListBox Grid.Column="1" BorderBrush="Black" Margin="15,20,10,15" MinHeight="25" Name="tbxFiles"
VerticalAlignment="Stretch"
ItemsSource="{Binding Items}"
SelectionMode="Multiple">
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="ListText" Text="{Binding}" Grid.Column="0"/>
<RadioButton Grid.Column="1" Content="TF" />
<RadioButton Grid.Column="2" Content="AF" />
<ComboBox Grid.Column="3" Text="Periode" />
<Button Grid.Column="4" Click="RemoveMark_Click" Content="Delete" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Resources>
</ListBox>
Every ListBox Item that gonna be created hass an deleteButton now and when I press this Button, this Code gonna be startet to Delete this Item:
PeriodeCombo.Items.Clear();
string required = tbxFiles.SelectedItems.Cast<string>().Aggregate((a, b) => a + b);
required = tbxFiles.SelectedItems.Cast<string>().Distinct()
.Aggregate((a, b) => a + b);
required = tbxFiles.SelectedItems.Cast<string>().Distinct()
.Aggregate((a, b) => a + ";" + b);
string[] words = required.Split(';');
foreach (var word in words)
{
temp1.Add(word);
}
for (int i = 0; i < temp1.Count; i++)
{
path.Remove(temp1[i]);
}
path.Remove(required);
tbxFiles.Items.Remove(tbxFiles.SelectedItem);
while (tbxFiles.SelectedItems.Count > 0)
{
tbxFiles.Items.Remove(tbxFiles.SelectedItems[0]);
}
And this Code remove only these item I clicked on that they are checked. But what I want to do now is that I can delete the Items without selecting by clicking the delete Button in that the Item are. So That when I click the delete button the Item gonna get deletet without to click on that item. How did I kneed to change my Code to get this working?