There is an abstract class Shape :
abstract class Shape { public string Name {get;set} } And the various classes of shapes that are inherited from Shape - Triangle , Circle , Square .
There is also a collection of shapes that binds to the ListBox :
public ObservableCollection<Shape> Shapes{get;set;} = new ObservableCollection<Shape>() { new Triangle {Name = "Треугольник"}, new Circle {Name = "Круг"}, new Circle {Name = "Круг"}, new Square {Name = "Квадрат"}, } Each object in the ListBox is represented by the Name property of the object and a button to which the command to remove an item from the collection is bound. Team one for all elements.
<ListBox.ItemTemplate> <DataTemplate> <Border> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Name}" /> <Button Grid.Column="1" Content="x" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=DataContext.RemoveShapeCommand}" CommandParameter="{Binding}" /> </Grid> </Border> </DataTemplate> </ListBox.ItemTemplate> The question is: The elements can have the same properties. How, in this case, to find the desired item that you want to delete?
Is it possible to get the index of the element that caused the command?