title: Expose DependencyProperty
body: <p>When developing WPF UserControls, what is the best way to expose a DependencyProperty of a child control as a DependencyProperty of the UserControl?  The following example shows how I would currently expose the Text property of a TextBox inside a UserControl. Surely there is a better / simpler way to accomplish this?</p>
  <pre class="lang-xml prettyprint-override"><code>    &lt;UserControl x:Class=&quot;WpfApplication3.UserControl1&quot;
          xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
          xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&gt;
          &lt;StackPanel Background=&quot;LightCyan&quot;&gt;
              &lt;TextBox Margin=&quot;8&quot; Text=&quot;{Binding Text, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}&quot; /&gt;
          &lt;/StackPanel&gt;
      &lt;/UserControl&gt;
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>    using System;
      using System.Windows;
      using System.Windows.Controls;
      
      namespace WpfApplication3
      {
          public partial class UserControl1 : UserControl
          {
              public static DependencyProperty TextProperty = DependencyProperty.Register(&quot;Text&quot;, typeof(string), typeof(UserControl1), new PropertyMetadata(null));
              public string Text
              {
                  get { return GetValue(TextProperty) as string; }
                  set { SetValue(TextProperty, value); }
              }
      
              public UserControl1() { InitializeComponent(); }
          }
      }
  </code></pre>