title: How to implement WPF User Control with UIElement dependency properties?
body: <p>I have a user control with this code behind:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// The text to use for the header.
  /// &lt;/summary&gt;
  public UIElement HeaderText
  {
      get { return (UIElement) GetValue(HeaderTextProperty); }
      set { SetValue(HeaderTextProperty, value); }
  }
  
  public static DependencyProperty HeaderTextProperty =
      DependencyProperty.Register("HeaderText",
                                  typeof(UIElement),
                                  typeof(Panel),
                                  new PropertyMetadata(null, new PropertyChangedCallback(HeaderTextPropertyChanged)));
  
  private static void HeaderTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  {
      var control = d as Panel;
      if (control != null)
      {
          control.HeaderText = (UIElement) e.NewValue;
      }
  }
  </code></pre>
  
  <p>And this XAML:</p>
  
  <pre><code>&lt;TextBlock Text="{TemplateBinding local:CustomPanel.HeaderText}" /&gt;
  </code></pre>
  
  <p>And I'm trying to use the user control like this:</p>
  
  <pre><code>&lt;controls:CustomPanel&gt;
      &lt;controls:CustomPanel.HeaderText&gt;
          &lt;TextBlock Text="Foo " /&gt;
          &lt;TextBlock Text="{Binding Bar}" /&gt;
          &lt;TextBlock Text=" baz." /&gt;
      &lt;/controls:CustomPanel.HeaderText&gt;
  &lt;/controls:CustomPanel&gt;
  </code></pre>
  
  <p>However, what I get is blank/empty text.</p>
  
  <p>I can get it to work if I change <code>UIElement</code> into <code>string</code> in code-behind, but <strong>I want to accept both <code>string</code>, <code>TextBlock</code></strong> and practically any <code>UIElement</code> that makes sense for text.</p>
  
  <p>How can I achieve this?</p>