title: XBF Error with DataTemplate in Application.Resources
body: <p><em>Universal Windows Platform app with Visual Studio 2015 (RTM)</em></p>
  
  <p>I have a DataTemplate that is used in multiple pages of my app, so I'd prefer to write it once and access it from anywhere I need to. In order to make it accessible by any page, I write it in my <code>App.xaml</code>'s <code>&lt;Application.Resources&gt;</code>:</p>
  
  <pre><code>&lt;Application
  x:Class="MyApp.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="using:MyApp"
  xmlns:viewmodels="using:MyApp.ViewModels"
  RequestedTheme="Light"&gt;
  
  &lt;Application.Resources&gt;
      &lt;DataTemplate x:Key="DetailContentTemplate" x:DataType="viewmodels:DataViewModel"&gt; 
      ...
      &lt;/DataTemplate&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>The DataTemplate portion of the code above works just fine in an individual page, but of course that means I'd have to copy and paste it multiple times to other pages, which just isn't efficient. However, I get this error when I use the DataTemplate in <code>App.xaml</code>:</p>
  
  <pre><code>XBF generation error code 0x09c4
  </code></pre>
  
  <p>I've determined that it stems from the <code>x:DataType="viewmodels:DataViewModel"</code> (without this, and hence, without any bindings the code works just fine). Looking up the error results in next to nothing. Is there a convenient workaround/solution to being able to reuse a DataTemplate with bindings in a Universal Windows Platform/WinRT app, preferably in XAML?</p>
  
  <p><strong>EDIT:</strong> As requested, the code in full for App.xaml.cs:</p>
  
  <pre><code>namespace MyApp
  {
  /// &lt;summary&gt;
  /// Provides application-specific behavior to supplement the default Application class.
  /// &lt;/summary&gt;
  sealed partial class App : Application
  {
      /// &lt;summary&gt;
      /// Allows tracking page views, exceptions and other telemetry through the Microsoft Application Insights service.
      /// &lt;/summary&gt;
      public static Microsoft.ApplicationInsights.TelemetryClient TelemetryClient;
  
      /// &lt;summary&gt;
      /// Initializes the singleton application object.  This is the first line of authored code
      /// executed, and as such is the logical equivalent of main() or WinMain().
      /// &lt;/summary&gt;
      public App()
      {
          TelemetryClient = new Microsoft.ApplicationInsights.TelemetryClient();
  
          this.InitializeComponent();
          this.Suspending += OnSuspending;
      }
  
      /// &lt;summary&gt;
      /// Invoked when the application is launched normally by the end user.  Other entry points
      /// will be used such as when the application is launched to open a specific file.
      /// &lt;/summary&gt;
      /// &lt;param name="e"&gt;Details about the launch request and process.&lt;/param&gt;
      protected override void OnLaunched(LaunchActivatedEventArgs e)
      {
          Frame rootFrame = Window.Current.Content as Frame;
  
          // Do not repeat app initialization when the Window already has content,
          // just ensure that the window is active
          if (rootFrame == null)
          {
              // Create a Frame to act as the navigation context and navigate to the first page
              rootFrame = new Frame();
              // Set the default language
              rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
  
              rootFrame.NavigationFailed += OnNavigationFailed;
  
              if (rootFrame.Content == null)
              {
                  rootFrame.Navigate(typeof(MasterDetailPage));
              }
  
              // Place the frame in the current Window
              Window.Current.Content = rootFrame;
          }
  
          // Ensure the current window is active
          Window.Current.Activate();
      }
  
      /// &lt;summary&gt;
      /// Invoked when Navigation to a certain page fails
      /// &lt;/summary&gt;
      /// &lt;param name="sender"&gt;The Frame which failed navigation&lt;/param&gt;
      /// &lt;param name="e"&gt;Details about the navigation failure&lt;/param&gt;
      void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
      {
          throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
      }
  
      /// &lt;summary&gt;
      /// Invoked when application execution is being suspended.  Application state is saved
      /// without knowing whether the application will be terminated or resumed with the contents
      /// of memory still intact.
      /// &lt;/summary&gt;
      /// &lt;param name="sender"&gt;The source of the suspend request.&lt;/param&gt;
      /// &lt;param name="e"&gt;Details about the suspend request.&lt;/param&gt;
      private void OnSuspending(object sender, SuspendingEventArgs e)
      {
          var deferral = e.SuspendingOperation.GetDeferral();
          //TODO: Save application state and stop any background activity
          deferral.Complete();
      }
  }
  </code></pre>
  
  <p>}</p>