title: ListView returning exception on load
body: <p>I have a listview for which I want to format several fields from a populating object.  Initially I created a data template which threw an InvalidOperationException with a blank page and no indication of the cause of the exception.  I found an article on CodeProject and I have the datatemplate now embedded in a Setter definition:</p>
  
  <pre><code>&lt;UserControl x:Class="Servpro.Framework.ViewerModule.Views.MenuView"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           mc:Ignorable="d" 
           d:DesignHeight="580" d:DesignWidth="210"&gt;
  &lt;UserControl.Resources&gt;
      &lt;Style TargetType="ListView"&gt;
          &lt;Setter Property="ItemTemplate"&gt;
              &lt;Setter.Value&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Vertical"&gt;
                          &lt;TextBlock 
                              Background="Transparent"
                              Foreground="Black" 
                              FontSize="12" 
                              Text="{Binding Path=CurrentEvent.EventTypeName, Mode=OneWay}" /&gt;
                          &lt;TextBlock 
                              Background="Transparent"
                              Foreground="Black" 
                              FontSize="12" 
                              Text="{Binding Path=CurrentEvent.EventMessage, Mode=OneWay}" /&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;
                              &lt;TextBlock 
                                  Background="Transparent" 
                                  Foreground="Black" 
                                  FontSize="8" 
                                  Text="{Binding Path=CurrentEvent.EventLoggedOn, Mode=OneWay}"
                                  Margin="0,0,10,0" /&gt;
                              &lt;TextBlock
                                  Background="Transparent" 
                                  Foreground="Black" 
                                  FontSize="8"
                                  Text="{Binding Path=CurrentEvent.Program, Mode=OneWay}" /&gt;
                              &lt;TextBlock 
                                  Background="Transparent" 
                                  Foreground="Black" 
                                  FontSize="8"
                                  Text=":" /&gt;
                              &lt;TextBlock 
                                  Background="Transparent" 
                                  Foreground="Black" 
                                  FontSize="8" 
                                  Text="{Binding Path=CurrentEvent.Method, Mode=OneWay}" /&gt;
                          &lt;/StackPanel&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  &lt;/UserControl.Resources&gt;
  &lt;Grid Margin="4"&gt;
      &lt;ListView 
          ItemsSource="{Binding Path=EventList, Mode=OneWay}" 
          Height="568" VerticalAlignment="Top" 
          Width="201" HorizontalAlignment="Left" 
          Margin="4" &gt;
          &lt;Border CornerRadius="11" /&gt;
          &lt;ListView.BorderBrush &gt;
              &lt;SolidColorBrush Color="#99FFFFFF" Opacity="0" /&gt;
          &lt;/ListView.BorderBrush&gt;
          &lt;ListView.Background&gt;
              &lt;SolidColorBrush Color="#99FFFFFF" Opacity="0"/&gt;
          &lt;/ListView.Background&gt;
      &lt;/ListView&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>With the definition ASIS I now get a runtime exception and it is finally pointing at the XAML.  But I still do not understand why I'm getting it.  The exception:</p>
  
  <p>'Add value to collection of type 'System.Windows.Controls.ItemCollection' threw an exception.' Line number '55' and line position '13'.</p>
  
  <p>It has the inner exception:</p>
  
  <p>{"Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead."}</p>
  
  <p>I'm clearly using ItemsSource so why am I getting this exception??</p>