title: Cannot find resource named 'X', why not?
body: <p>I want to create a wizard UI for inventories management. The relevant line in the xaml is:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ContentPresenter Content="{Binding Current}" ContentTemplateSelector="{StaticResource inventorySelector}"/&gt;
  </code></pre>
  
  <p>"Current" is the currently active view model, one of AvailableInventoriesViewModel, GroupsViewModel, NewArticlesViewModel, ResultViewModel. The DataTemplateSelector I have defined as such:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System.Diagnostics;
  using System.Windows;
  using System.Windows.Controls;
  using Centron.WPF.WarehousingExtension.InventoryModule.ViewModels.WizardViewModels;
  
  namespace Centron.WPF.WarehousingExtension.InventoryModule.UI.DataTemplateSelectors
  {
      public class InventoryDatatemplateSelector : DataTemplateSelector
      {
          public DataTemplate AvailableDatatype { get; set; }
          public DataTemplate GroupsDatatype { get; set; }
          public DataTemplate NewDatatype { get; set; }
          public DataTemplate ResultDatatype { get; set; }
  
          public InventoryDatatemplateSelector()
          {
              Debug.WriteLine("");
          }
  
          public override DataTemplate SelectTemplate(object item, DependencyObject container)
          {
              if (item is AvailableInventoriesViewModel)
                  return AvailableDatatype;
              else if (item is GroupsViewModel)
                  return GroupsDatatype;
              else if (item is NewArticlesViewModel)
                  return NewDatatype;
              else return ResultDatatype;
          }
      }
  }
  </code></pre>
  
  <p>Then I create instances of the DataTemplates and a Selector like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;base:InventoryViewBase.Resources&gt;
      &lt;DataTemplate DataType="viewModels:AvailableInventoriesViewModel" x:Key="availableInventoriesDatatype"&gt;
          &lt;controls:AvailableInventoriesView /&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate DataType="viewModels:GroupsViewModel" x:Key="groupsDatatype"&gt;
          &lt;controls:GroupsView /&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate DataType="viewModels:NewArticlesViewModel" x:Key="newArticlesDatatype"&gt;
          &lt;controls:NewArticlesView /&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate DataType="viewModels:ResultViewModel" x:Key="resultDatatype"&gt;
          &lt;controls:ResultView/&gt;
      &lt;/DataTemplate&gt;
      &lt;selector:InventoryDatatemplateSelector
              x:Key="inventorySelector" 
              AvailableDatatype="{StaticResource availableInventoriesDatatype}"
              GroupsDatatype="{StaticResource groupsDatatype}"
              NewDatatype="{StaticResource newArticlesDatatype}"
              ResultDatatype="{StaticResource resultDatatype}"/&gt;
  &lt;/base:InventoryViewBase.Resources&gt;
  </code></pre>
  
  <p>I set a breakpoint in the constructor of my InventoryDatatemplateSelector, and can step through it, but in the next Debug step, apparently when it tries to set the first property of that selector instance, I immediately get an exception with inner exception:</p>
  
  <blockquote>
    <p>Cannot find resource named \"availableInventoriesDatatype\". Resource names are case sensitive.</p>
  </blockquote>
  
  <p>What's the deal, why is the resource not found when it's clearly defined?</p>