title: WPF ObservableCollection in xaml
body: <p>I have created an ObservableCollection in the code behind of a user control. It is created when the window loads:</p>
  
  <pre><code>    private void UserControl_Loaded(object sender, RoutedEventArgs e)
      {
          Entities db = new Entities();
          ObservableCollection&lt;Image&gt; _imageCollection =
         new ObservableCollection&lt;Image&gt;();
  
          IEnumerable&lt;library&gt; libraryQuery =
          from c in db.ElectricalLibraries
  
          select c;
  
          foreach (ElectricalLibrary c in libraryQuery)
          {
              Image finalImage = new Image();
              finalImage.Width = 80;
  
              BitmapImage logo = new BitmapImage();
              logo.BeginInit();
              logo.UriSource = new Uri(c.url);
              logo.EndInit();
  
              finalImage.Source = logo;
  
              _imageCollection.Add(finalImage);
  
          }
  
      }
  </code></pre>
  
  <p>I need to get the ObservableCollection of images which are created based on the url saved in a database. But I need a ListView or other ItemsControl to bind to it in XAML file like this:</p>
  
  <p></p>
  
  <p>But I can't figure it out how to pass the ObservableCollection to the ItemsSource of that control. I tried to create a class and then create an instance of a class in xaml file but it did not work. Should I create a static resource somehow></p>
  
  <p>Any help will be greatly appreciated.</p>