title: Why wont my custom WPF control property work when bound to a view model?
body: <p>My custom control wont work when I have it bound like this (The text block displays my view model property <code>Test</code> fine, but my custom control displays the default value <code>empty</code>):</p>
  
  <pre><code>&lt;local:DynamicMenu Text="{Binding Test}"/&gt;
  &lt;TextBlock Text="{Binding Test}"&gt;&lt;/TextBlock&gt;
  </code></pre>
  
  <p>If I have a static value it does work though:</p>
  
  <pre><code>&lt;local:DynamicMenu Text="test"/&gt;
  &lt;TextBlock Text="{Binding Test}"&gt;&lt;/TextBlock&gt;
  </code></pre>
  
  <p>It is implemented as such. I would prefer a solution that would make it work like the TextBlock.</p>
  
  <p><strong>.Xaml.CS</strong></p>
  
  <pre><code>public partial class DynamicMenu : UserControl
  {
      public static readonly DependencyProperty TextProperty =
          DependencyProperty.Register("Text",
              typeof(string),
              typeof(DynamicMenu),
              new FrameworkPropertyMetadata("Empty",
                  FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
  
      public DynamicMenu()
      {
          InitializeComponent();
      }
  
      public string Text
      {
          get { return (string)GetValue(TextProperty); }
          set { SetValue(TextProperty, value); }
      }
  
  }
  </code></pre>
  
  <p><strong>.Xaml</strong></p>
  
  <pre><code>&lt;UserControl x:Class="Whelen.Griffin.Views.DynamicMenu"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               mc:Ignorable="d" 
               d:DesignHeight="300" d:DesignWidth="300" 
               DataContext="{Binding RelativeSource={RelativeSource Self}}" &gt;
      &lt;TextBlock Text="{Binding Text}"&gt;&lt;/TextBlock&gt;
  &lt;/UserControl&gt;
  </code></pre>