title: WPF - Binding in ListView's ItemsSource cannot be a List
body: <p>I have a WPF application that I try to code using MVVM.The goal is to make something like a notification center, that lists different types of data.</p>
  
  <p>To do this, I want to fill a ListView on the main page with different ViewModels. One ViewModel for each type of data.</p>
  
  <p>The problem is:
  When I put a (not a list) ViewModel in my ListView, it works fine. But if I put a list in my ListView, the program crashes on startup. I need the ListView to take a list (ObservableCollection perhaps) of mixed ViewModels.</p>
  
  <p>I receive the error “Items collection must be empty before using ItemsSource.” at a seemingly random location in my code. Completely removing the code where the exception appears just causes it to show somewhere else.</p>
  
  <p>I have the following:</p>
  
  <p><strong>C#:</strong></p>
  
  <pre><code>public class MainViewModel : ObservableObject
  {
      private List&lt;IPageViewModel&gt; _items;
  
      public MainViewModel()
      {
          _items = new List&lt;IPageViewModel&gt;
          {
              new StatusViewModel(),
              new SettingsViewModel(),
              new OverviewViewModel()
          };
      }
  
      public List&lt;IPageViewModel&gt; Items =&gt; _items ?? (_items = newList&lt;IPageViewModel&gt;());
  }
  </code></pre>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="InfoCenter.Views.Main.MainView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:test="clr-namespace:InfoCenter.Views.Test"
          xmlns:main="clr-namespace:InfoCenter.Views.Main"
          xmlns:views="clr-namespace:InfoCenter.Views"
          xmlns:settings="clr-namespace:InfoCenter.Views.Settings"
          xmlns:status="clr-namespace:InfoCenter.Views.Status"
          xmlns:overview="clr-namespace:InfoCenter.Views.Overview"
          mc:Ignorable="d"
          Title="MainView" Height="450" Width="500" 
          MaxWidth="1920"
          WindowStyle="None" Loaded="MainViewLoaded" 
          SizeChanged="MainViewSizeChanged"
          PreviewKeyDown="OnPreviewKeyDown"
          GotFocus="OnGotFocus"
          Closing="OnClosing"
          ResizeMode="NoResize"
          d:DataContext="{d:DesignInstance main:MainViewModel}"&gt;
  
      &lt;Window.Resources&gt;
          &lt;DataTemplate DataType="{x:Type overview:OverviewViewModel}"&gt;
              &lt;overview:OverviewView /&gt;
          &lt;/DataTemplate&gt;
          &lt;DataTemplate DataType="{x:Type status:StatusViewModel}"&gt;
              &lt;status:StatusView /&gt;
          &lt;/DataTemplate&gt;
          &lt;DataTemplate DataType="{x:Type settings:SettingsViewModel}"&gt;
              &lt;settings:SettingsView /&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt;
  
  
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="24" /&gt;
              &lt;RowDefinition Height="*" /&gt;
              &lt;RowDefinition Height="30" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*" /&gt;
              &lt;ColumnDefinition Width="24" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;Button Command="{Binding ButtonClickCommand}" CommandParameter="Minimize" Grid.Row="0" Grid.Column="1"&gt;
              &lt;Image Source="/Resources/arrow-down-1.png"&gt;&lt;/Image&gt;
          &lt;/Button&gt;
  
          &lt;ListView ItemsSource="{Binding Items}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" ScrollViewer.HorizontalScrollBarVisibility="Hidden" PreviewMouseWheel="OnPreviewMouseWheel" ScrollViewer.VerticalScrollBarVisibility="Hidden"&gt;
              &lt;Grid&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition Height="30" /&gt;
                      &lt;RowDefinition Height="Auto" /&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="*" /&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
  
                  &lt;Label Grid.Row="0" Grid.Column="0" Content="{Binding Path=Items.Header}" /&gt;
                  &lt;ContentControl Grid.Row="1" Grid.Column="0" Content="{Binding}" /&gt;
              &lt;/Grid&gt;
  
          &lt;/ListView&gt;
  
          &lt;StatusBar FlowDirection="RightToLeft" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"&gt;
              &lt;Image Width="24" Height="24" Source="{Binding ConnectionIcon}" /&gt;
          &lt;/StatusBar&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I really hope that you can help. I have been trying to fix it the whole day!</p>