title: Defining data source declaratively in XAML
body: <p>I have list controls with small, static data sources. For example:</p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding Countries}" .../&gt;
  </code></pre>
  
  <p>and my view model populates the list:</p>
  
  <pre><code>this.Countries.Add(new Country { Code = "BE", Name = "Belgium" });
  this.Countries.Add(new Country { Code = "CA", Name = "Canada" });
  // etc.
  </code></pre>
  
  <p>Is there an alternative way to define the list contents in XAML instead? Something like:</p>
  
  <pre><code>&lt;ItemsControl&gt;
      &lt;ItemsControl.ItemsSource&gt;
          &lt;somenamespace:list&gt;
              &lt;mynamespace:Country Code="BE" Name="Belgium" /&gt;
              etc.
          &lt;/somenamespace:list&gt;
      &lt;/ItemsControl.ItemsSource&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>I would actually put the lists in separate resource files and would hope to do <code>ItemsSource="{StaticResource myListOfCountries}"</code> after defining them as a resource.</p>
  
  <p>I want to do this to lighten the boilerplate code in my VMs. I wonder if it would negatively affect performance as those objects could be created before the view is rendered, while I could otherwise load these later (on navigated to, on view load, ... vs contructor). Any thoughts welcome!</p>