title: WPF throwing warning on Dictionary Collection Changed in .Net 4.5.1
body: <p>I was using .Net 4.0 and had a <code>Dictionary</code> in my code like the one below</p>
  
  <pre><code> public Dictionary&lt;DirectoryInfo, ObservableCollection&lt;Media&gt;&gt; FoldersDictionary
  </code></pre>
  
  <p>I am using this dictionary of to display the folders from windows directory in a surface list box. <code>DirectoryInfo</code> will contain the directory information about folders e.g their names and <code>Media</code> class will contain the data inside these folders.</p>
  
  <p>When I add or remove items from the <code>ObservableCollection</code> in my <code>Dictionary</code>, WPF threw this warning at me:     </p>
  
  <pre><code>Collection of type 'System.Collections.Generic.Dictionary`2[[System.IO.DirectoryInfo, 
  mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],
  [System.Collections.ObjectModel.ObservableCollection`1[[Media, ViewModel, 
  Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System, Version=4.0.0.0, 
  Culture=neutral, PublicKeyToken=b77a5c561934e089]]' has been changed without raising
  a CollectionChanged event.  Support for this is incomplete and inconsistent, 
  and will be removed completely in a future version of WPF. Consider either (a) 
  implementing INotifyCollectionChanged, or (b) avoiding changes to this type of 
  collection`.
  </code></pre>
  
  <p>However I ignored this warning as my output was showing up alright. Yesterday I upgraded to .Net 4.5.1 on Windows 7 and ran this code. The warning was still the same but now every time I refresh my dictionary (meaning clearing it and then adding new stuff to <code>ObservableCollection</code>), the last <code>ObservableCollection</code> item is never visible on my UI. I debugged my code and found out that the <code>Dictionary</code> infact still has the last item added in it, its just that it is not being displayed on my WPF XAML UI. I wondered may be this behavior is due to the warning I see. I implemented the following <code>CollectionChanged</code> event to my code:</p>
  
  <pre><code> private void OnUrlChanged(string newUrl)
          {
              if (string.IsNullOrEmpty(newUrl)) 
                  return;
  
              var directoryInfo = new DirectoryInfo(newUrl);
              DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
  
              if (directoryInfos.Any())
              {
                  if (FoldersDictionary != null &amp;&amp; FoldersDictionary.Any())
                  {
                       FoldersDictionary.Clear();
                  }
  
                  FoldersDictionary = null;
                  FoldersDictionary = new Dictionary&lt;DirectoryInfo, ObservableCollection&lt;Media&gt;&gt;();
                  LoadFolders(FoldersDictionary, directoryInfos);
              }     
          }
  
   private void LoadFolders( Dictionary&lt;DirectoryInfo, ObservableCollection&lt;Media&gt;&gt; Folders, IEnumerable&lt;DirectoryInfo&gt; directoryInfos)
          {
              foreach (DirectoryInfo item in directoryInfos)
              {
                  ObservableCollection&lt;Media&gt; medias = LoadMedias(item.FullName);
  
                  //new code starts here
              medias.CollectionChanged+=new System.Collections.Specialized.NotifyCollectionChangedEventHandler(medias_CollectionChanged); 
                  //new code ends here
  
                  if (medias != null)
                  {
                      Folders.Add(item, medias);
                  }
              }
          }
  
  //new code starts here
          void medias_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
          {
               //do nothing
          }
  
  //new code ends here
  </code></pre>
  
  <p>My <code>Dictionary</code> <code>PropertyChanged</code> is given as:</p>
  
  <pre><code>        public const string FoldersDictionaryPropertyName = "FoldersDictionary";
  
          private Dictionary&lt;DirectoryInfo, ObservableCollection&lt;Media&gt;&gt; _foldersDictionary;
  
          public Dictionary&lt;DirectoryInfo, ObservableCollection&lt;Media&gt;&gt; FoldersDictionary
          {
              get { return _foldersDictionary; }
  
              set
              {
                  if (_foldersDictionary == value)
                  {
                      return;
                  }
  
                  Dictionary&lt;DirectoryInfo, ObservableCollection&lt;Media&gt;&gt; oldValue = _foldersDictionary;
                  _foldersDictionary = value;
  
  
  
                  RaisePropertyChanged(FoldersDictionaryPropertyName);
  
  
              }
          }
  </code></pre>
  
  <p>This is the XAML I am using. </p>
  
  <pre><code>&lt;Grid Height="180"&gt;
                      &lt;s:SurfaceListBox x:Name="xFoldersListBox"
                                        Background="{x:Null}"
                                        ItemContainerStyle="{StaticResource                             SurfaceListBoxItemSquareStyle}" 
                                        ItemsSource="{Binding FoldersDictionary}"
                                        ItemTemplate="{StaticResource FolderDataTemplate}"
                                        SelectedValuePath="Value"
                                        Template="{StaticResource SurfaceListBoxHorizontalTemplate}" /&gt;
   &lt;/Grid&gt;
  
  
  &lt;DataTemplate x:Key="FolderDataTemplate"&gt;
              &lt;s:SurfaceToggleButton IsChecked="{Binding IsSelected,
                                                         Mode=TwoWay,
                                                         RelativeSource={RelativeSource   Mode=FindAncestor, AncestorType={x:Type s:SurfaceListBoxItem}}}" Style="{StaticResource ToggleButtonStyle}"&gt;
                  &lt;TextBlock Text="{Binding Path=Key.Name}"
                             TextAlignment="Center"
                             TextWrapping="Wrap" /&gt;
              &lt;/s:SurfaceToggleButton&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>However I am still getting the same warning as before and further more I cant see my last folder in my dictionary being displayed at all when I clear and repopulate my <code>Dictionary</code>. Any idea what may be causing this behaviour?</p>