tags:

views:

65

answers:

1

I got exception : Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.

A: 

You must add the items to your source-collection that is set to ItemsSource. After you have set the ItemsSource-property to a value, its no more possible to use the Items-property (besides you set ItemsSource newly to null). Items and ItemsSource exclude each other.

If you use ItemsSource, your source-collection must implement INotifyCollectionChanged so that it will inform the ListView about changes. If not, added items to it will not change the ListView. E.g. if you use List<T> as items-source, changes will not be forwarded.

There exist classes that do that for you such as ObservableCollection<T>.

HCL
I used Observable collection but it display same error
mandarBadve
Do you use yourListView.Items.Add(newItem) or myObservableCollection.Add(newItem)
HCL
Thank you Now Its run comfortably
mandarBadve
If it helped you, please mark the answer as accepted by checking the checkmark under the Points-display.
HCL