WPF Error: “Items collection must be empty before using ItemsSource.”


Does anyone know why I keep getting the "Items collection must be empty before using ItemsSource"-Error?

Here is the code:

        <ScrollViewer Margin="8,8,8,8" Grid.Row="3" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">                  
                <WrapPanel Orientation="Vertical">
                    <ItemsControl ItemsSource="{Binding}" x:Name="CustomerList" >>
                                <WrapPanel Orientation="Horizontal">

This is what I do in my Code-Behind:

 CustomerList.ItemsSource = _mainViewModel.CustomerCollection;

Note that CustomerCollection is just a simple List<Customers>.

Thanks for your help!


Best Solution

Is this code copied verbatim? Do you really have two right angle brackets (>>) at the end of the <ItemsControl... line? If so, the second right angle bracket might be getting treated as text content, which is getting added to the Items collection.

Related Question