WPF "Items collection must be empty before using ItemsSource" fix
Codemia Knowledge Hub ·
WPF throws Items collection must be empty before using ItemsSource when a control such as ListBox, ComboBox or ItemsControl is given items in two ways at once. A control can either hold explicit children in its Items collection or be bound through ItemsSource, never both. Remove the hardcoded items if the control should be data-bound, or drop ItemsSource if the list is static.
Items and ItemsSource are mutually exclusive
WPF item controls support two approaches:
- add items directly in XAML or code through the
Itemscollection - bind the control to a source collection through
ItemsSource
This is invalid, because the control has a hardcoded item and also binds ItemsSource:
WPF cannot merge the two, so it throws.
Bind with ItemsSource only
If the control shows data from your view model, remove the declared items and bind only through ItemsSource:
This is the right model for dynamic and MVVM-style lists: the control is a view over the bound collection. In MVVM, let that collection own the item set completely and avoid manipulating items in the view.
Use Items only for static lists
If the list is fixed and needs no binding, do not set ItemsSource:
That is fine for small static menus or demo screens.
Clear Items before assigning ItemsSource in code
The error also appears when code adds items manually and later assigns ItemsSource:
If you really need to switch to a bound source, clear the items first:
In well-structured WPF code you normally pick one mode and keep it.
Look for hidden child items in XAML
The cause is not always an obvious ListBoxItem. Check for:
- child elements in the control's XAML that you forgot about
- a custom control template that injects item children
- placeholder items left in XAML copied from an example
If ItemsSource is meant to be the source of truth, remove every direct item declaration.
Customize display with ItemTemplate, not child elements
A frequent mistake is adding child items to get custom rendering. To control how each bound item looks, use ItemTemplate:
The data still comes from ItemsSource; the template only controls presentation and does not replace the data source.
Related reading
- IUnityContainer.ResolveT throws error claiming it cannot be used with type parameters
- Java Equivalent of C async/await?
- Java equivalent to C extension methods
- Java equivalent to
- itgendid012 Last part of the SQL statement has not been recognized on distributed Exact Online query
- iTunes account creation not allowed when trying to test In-App Purchases
- Java Future vs c async await
- Java System.currentTimeMillis equivalent in C

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.