title: OnApplyTemplate is not being called
body: <p>I have a solution with 2 projects: Windows Phone App and a Windows Phone Class Library. The class library has a control called MessageBoxExtended which inherits from ContentControl. The project also has a Themes folder with a generic.xaml file. The file has the Build Action set to Page and it looks like this:</p>
  
  <pre><code>&lt;ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:KontactU.Common.WPControls;assembly=KontactU.Common.WPControls"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  mc:Ignorable="d"&gt;
  &lt;Style TargetType="local:MessageBoxExtended"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="local:MessageBoxExtended"&gt;
                  &lt;Grid x:Name="LayoutRoot"&gt;
                  &lt;StackPanel&gt;
                          &lt;TextBlock x:Name="lblTitle" Text="Title Goes Here" Style="{StaticResource PhoneTextTitle3Style}"/&gt;
                          &lt;TextBlock x:Name="lblMessage" Text="Some long message here repeated over and over again. Some long message here repeated over and over again. " TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" /&gt;
                          &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Center"&gt;
                              &lt;Button x:Name="btnLeft" Content="Button1" Click="btnLeft_Click"&gt;&lt;/Button&gt;
                              &lt;Button x:Name="btnCenter" Content="Button2" Click="btnCenter_Click"&gt;&lt;/Button&gt;
                              &lt;Button x:Name="btnRight" Content="Button3" Click="btnRight_Click"&gt;&lt;/Button&gt;
                          &lt;/StackPanel&gt;
                      &lt;/StackPanel&gt;
                  &lt;/Grid&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p></p>
  
  <p>The control code looks like this:</p>
  
  <pre><code> public class MessageBoxExtended : ContentControl
  {
      private TextBlock lblTitle;
      private TextBlock lblMessage;
      private Button btnLeft;
      private Button btnCenter;
      private Button btnRight;
  
      private bool currentSystemTrayState;
  
      internal Popup ChildWindowPopup
      {
          get;
          private set;
      }
  
      private static PhoneApplicationFrame RootVisual
      {
          get
          {
              return Application.Current == null ? null : Application.Current.RootVisual as PhoneApplicationFrame;
          }
      }
  
      public MessageBoxExtended()
          : base()
      {
          DefaultStyleKey = typeof(MessageBoxExtended);
      }
  
      public override void OnApplyTemplate()
      {
          base.OnApplyTemplate();
          lblTitle = this.GetTemplateChild("lblTitle") as TextBlock;
          lblMessage = this.GetTemplateChild("lblMessage") as TextBlock;
          btnLeft = this.GetTemplateChild("btnLeft") as Button;
          btnCenter = this.GetTemplateChild("btnCenter") as Button;
          btnRight = this.GetTemplateChild("btnRight") as Button;
  
          InitializeMessageBoxExtended("Title", "Message", MessageBoxExtendedButtonType.Ok);
      }
  
      private void InitializeMessageBoxExtended(string title, string message, MessageBoxExtendedButtonType buttonType)
      {
          HideSystemTray();
          lblTitle.Text = title;
          lblMessage.Text = message;
  
          switch (buttonType)
          {
              case MessageBoxExtendedButtonType.Ok:
                  btnLeft.Visibility = System.Windows.Visibility.Collapsed;
                  btnRight.Visibility = System.Windows.Visibility.Collapsed;
                  btnCenter.Content = "ok";
                  break;
              case MessageBoxExtendedButtonType.OkCancel:
                  btnCenter.Visibility = System.Windows.Visibility.Collapsed;
                  btnLeft.Content = "ok";
                  btnRight.Content = "cancel";
                  break;
              case MessageBoxExtendedButtonType.YesNo:
                  btnCenter.Visibility = System.Windows.Visibility.Collapsed;
                  btnLeft.Content = "yes";
                  btnRight.Content = "no";
                  break;
          }
      }
  
      public void Show(string title, string message, MessageBoxExtendedButtonType buttonType)
      {
          if (ChildWindowPopup == null)
          {
              ChildWindowPopup = new Popup();
  
              try
              {
                  ChildWindowPopup.Child = this;
              }
              catch (ArgumentException)
              {
                  throw new InvalidOperationException("The control is already shown.");
              }
          }
  
          if (ChildWindowPopup != null &amp;&amp; Application.Current.RootVisual != null)
          {
              // Configure accordingly to the type
              InitializeMessageBoxExtended(title, message, buttonType);
  
              // Show popup
              ChildWindowPopup.IsOpen = true;
          }
      }
  
      private void HideSystemTray()
      {
          // Capture current state of the system tray
          this.currentSystemTrayState = SystemTray.IsVisible;
          // Hide it
          SystemTray.IsVisible = false;
      }
  }
  </code></pre>
  
  <p>The Windows Phone App references it and calls it in the code behind by instantiating it and calling the Show method:</p>
  
  <pre><code>MessageBoxExtended mbe = new MessageBoxExtended();
  mbe.Show();
  </code></pre>
  
  <p>The problem is that the OnApplyTemplate is never called. I've tried commenting out all the lines in the generic.xaml, but I get the same result. </p>
  
  <p>Any ideas?</p>