How to clear a collection if in this way it is impossible to do the cleaning.
listbox.itemsource = collect.clear(); How to clear a collection if in this way it is impossible to do the cleaning.
listbox.itemsource = collect.clear(); ListBox cannot find out if the collection has been cleared. There are no alerts for this. In WPF, when binding the ObservableCollection collection, the ListBox learns about changes. In the indicated case, if a regular List or Array is bound, you just need to clear the collection and resubmit it to the ListBox.
// неправильная версия (т.к. ссылка не изменилась, обновления списка не произойдет) collect.clear(); listbox.ItemsSource = collect; UPD: Indeed, I am a little misled (thanks to the commentators :)). Clearing the list is an expensive operation, you should not do it at all, but simply pass a link to a new blank sheet:
listbox.ItemsSource = new List<string>(); if you need to filter the sheet, and not clear, you can do this:
listbox.ItemsSource = collect.Where(x=>условие).ToList(); ObservableCollection<string> items = ObservableCollection<string>(); listbox.ItemsSource = items; clean items . This is a reference data type, doing so:
items.Clear(); the result will also be visible in listbox.ItemsSource, since the reference values of listbox.ItemsSource and items same.
Source: https://ru.stackoverflow.com/questions/600545/
All Articles
clearmethod? if it was supposed to be theClearmethod, then it is incorrectly written, and in addition, this method returns nothing. What does it mean to clear the collection ? delete all items? you can simply assign a new empty collection to itemsource - Grundy