The program uses several ItemsControl with an overridden style, the elements of which are buttons that do roughly the same thing: by clicking on a button, the selected item should be removed from the collection bound to the ItemsSource .
Due to the fact that different collections are attached, for each ItemsControl I make my removal team. And each ItemsControl in my looks like this:
<ItemsControl ItemsSource="{Binding MyCollection}" > <ItemsControl.Style> <Style TargetType="{x:Type ItemsControl}" BasedOn="{StaticResource ItemsControlMainStyle}"> <Setter Property="ItemContainerStyle"> <Setter.Value> <Style TargetType="ContentPresenter"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <Button Content="{Binding}" Command="{Binding ElementName=mainWindow, Path=DataContext.OperationsVM.RemoveElementCommand}" /> </DataTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> </Style> </ItemsControl.Style> </ItemsControl> That is, I supplement the main ItemsControlMainStyle style and bind the necessary command. The code is very bulky. Intuitively, it seems that you can make everything more concisely and bring this piece of code with the style and binding of the commands into ItemsControlMainStyle , and take the necessary command from the property. But with the implementation of this approach, I have problems, because ItemsControl does not have a Command property.
Tell me how to do this (and can it)?

Из-за того, что привязываются разные коллекцииare tied - user227049ObservableCollectionin theViewModel, which are bound to 4th differentItemsControl. Each element is represented by a button, by clicking on which the element should be removed from the associated collection. - trydex