title: Binding not working against application resource
body: <p>I have an application in which I'd like to have a single instance of a collection of items that can be accessed by more than one view model, where each view model is associated with exactly one view.  To accomplish this, I have put the collection into an application resource to which the view model obtains a reference in its constructor, which it makes available as a public property.</p>
  
  <p>I have a ListBox in the view that has its DataContext set to the view model, then its ItemsSource is set to the view model property that references the collection in the application.  The ListItems, then, bind to properties of the item within the collection.</p>
  
  <p>Unfortunately, while the collection gets populated, the ListBox does not.</p>
  
  <p>Here's the App.xaml:</p>
  
  <pre><code>    &lt;Application x:Class="TestBindingToAppResource.App"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:TestBindingToAppResource"
          StartupUri="MainWindow.xaml"&gt;
      &lt;Application.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
              &lt;!--Declaring this here so that a single instance of the people list is available to the entire application.--&gt;
              &lt;local:People x:Key="MyPeople"/&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>And the individual item and its collection:</p>
  
  <pre><code>    using System;
  using System.Collections.ObjectModel;
  using System.ComponentModel;
  using System.Runtime.CompilerServices;
  
  namespace TestBindingToAppResource
  {
      // Contains the data for a single person.
      public class Person : INotifyPropertyChanged
      {
          private string theFirstName;
          public string FirstName { get { return theFirstName; }  set { if (value != theFirstName) { theFirstName = value; NotifyPropertyChanged(); } } }
  
          private string theLastName;
          public string LastName { get { return theLastName; } set { if (value != theLastName) { theLastName = value; NotifyPropertyChanged(); } } }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          public Person()
          {
              FirstName = "John";
              LastName = "Doe";
          }
  
          public Person(string firstName, string lastName)
          {
              FirstName = firstName;
              LastName = lastName;
          }
  
          private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
          {
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  
      public class People : ObservableCollection&lt;Person&gt;
      {
          public People()
          {
  
          }
      }
  }
  </code></pre>
  
  <p>The main window merely contains a UserControl that contains the list.</p>
  
  <pre><code>    &lt;Window x:Class="TestBindingToAppResource.MainWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:local="clr-namespace:TestBindingToAppResource"
                  Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;local:PeopleList x:Name="ListOfPeople"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Here's the UserControl that contains the ListBox:</p>
  
  <pre><code>    &lt;UserControl x:Class="TestBindingToAppResource.PeopleList"
               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" 
               xmlns:local="clr-namespace:TestBindingToAppResource"
               mc:Ignorable="d" 
               d:DesignHeight="450" d:DesignWidth="800"&gt;
      &lt;UserControl.DataContext&gt;
          &lt;local:PeopleViewModel/&gt;
      &lt;/UserControl.DataContext&gt;
      &lt;Grid&gt;
          &lt;!--... Other objects ...--&gt;
          &lt;StackPanel Orientation="Vertical" Margin="5,5,5,5"&gt;
              &lt;TextBlock Text="Here's a list of people"/&gt;
              &lt;ListBox Name="ListOfPeople" ItemsSource="{Binding People}" Margin="5,0,5,5"&gt;
                  &lt;ListBox.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;
                              &lt;TextBlock Name="theFirstName" Text="{Binding FirstName}" Margin="5,5,5,5"/&gt;
                              &lt;TextBlock Name="theLastName" Text="{Binding LastName}" Margin="0,5,5,5"/&gt;
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListBox.ItemTemplate&gt;
              &lt;/ListBox&gt;
              &lt;!--... Other objects ...--&gt;
          &lt;/StackPanel&gt;
          &lt;!--... Other objects ...--&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Finally, here's the view model that ties them together:</p>
  
  <pre><code>    using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  
  namespace TestBindingToAppResource
  {
      // A view model that allows the list in the view to access the people list in the model.
  
      public class PeopleViewModel
      {
          public People thePeople { get; private set; }
  
          public PeopleViewModel()
          {
              // A single instance of the people array is instantiated in the Application object as a resource.
              // This allows any number of view models to access a single instance of the data model.
  
              thePeople = (People)Application.Current.Resources["MyPeople"];
  
              // The view model should load the people collection.
  
              LoadThePeople(thePeople);
          }
  
          private void LoadThePeople (People thePeople)
          {
              thePeople.Add(new Person("Adam", "Baker"));
              thePeople.Add(new Person("Cindy", "Douglas"));
              thePeople.Add(new Person("Edward", "Fox"));
              thePeople.Add(new Person("Gloria", "Herbst"));
          }
      }
  }
  </code></pre>
  
  <p>Here's the results:</p>
  
  <p><a href="https://i.stack.imgur.com/yPTSJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yPTSJ.png" alt="enter image description here"></a></p>
  
  <p>So, my main question is, of course, why isn't this working?</p>
  
  <p>But, I believe that many people have the same goal of having a single instance of the data model that can be accessed by a number of view models throughout the application.  How is this typically done?</p>
  
  <p>I am using:</p>
  
  <ul>
  <li>WPF</li>
  <li>C#</li>
  <li>Win10</li>
  <li>VS 2019 Community</li>
  </ul>