There is a listbox and ItemControl (shopControl). When I click on the listbox, I get the name of the clicked element (title). In shopControl is a collection of items.
Elements = new ObservableCollection<ShopItem>(); When the name of the element is received - I compare all the elements, leave only those that contain (title), delete the rest.
var list = (ListBox)sender; TodoItem catTitle = (TodoItem)list.SelectedItem; string title = catTitle.Title.ToLower(); for (int n = Elements.Count - 1; n >= 0; --n) { if (!Elements[n].Slot.Contains(title)) { Elements.RemoveAt(n); } } When you re-select an item in the list box - all other items disappear (since the rest were deleted initially) and I get an empty control. How to hide unnecessary elements without deleting, and display only the ones I need?