1
Answer

Clear WPF ListBox which is bind to a list

TAN WhoAMI

TAN WhoAMI

12y
5.4k
1
I am trying to clear and populate the WPF ListBox with new values at each click of the button, but apparently, I cannot clear it because it is bind to some list.

error message is as below when the commented line is there:
Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.

My source code is as attached.

Appreciate any useful help.

================================

I have found the answer. Replace the commented line with

lucky_listBox.ItemsSource =

null;

Attachment: code.zip

Answers (1)