title: UWP Two-way binding in a control template
body: <p>I'm having a custom control with a Text property which should be two-way bind to a property of the data context.<br />
  The binding happens only at the beginning (one-time I guess) but doesn't respond to any text change.</p>
  
  <p>my custom control:</p>
  
  <pre><code>public sealed class MyTextControl : Control
  {
      public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
          "Text", typeof(string), typeof(MyTextControl), new PropertyMetadata(default(string)));
  
      public string Text
      {
          get =&gt; (string)GetValue(TextProperty);
          set =&gt; SetValue(TextProperty, value);
      }
  
      public MyTextControl()
      {
          DefaultStyleKey = typeof(MyTextControl);
      }
  }
  </code></pre>
  
  <p>the control template:</p>
  
  <pre><code>&lt;Style TargetType="local:MyTextControl"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="local:MyTextControl"&gt;
                  &lt;Border
                      Background="{TemplateBinding Background}"
                      BorderBrush="{TemplateBinding BorderBrush}"
                      BorderThickness="{TemplateBinding BorderThickness}"&gt;
  
                      &lt;TextBox
                          BorderBrush="Black"
                          BorderThickness="1"
                          Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" /&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>i'm calling to the control:</p>
  
  <pre><code>&lt;StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
      &lt;myTextControl:MyTextControl
          Width="500"
          HorizontalAlignment="Center"
          VerticalAlignment="Center"
          Text="{x:Bind Greeting, Mode=TwoWay}" /&gt;
  
      &lt;Button
          Margin="50"
          HorizontalAlignment="Center"
          VerticalAlignment="Center"
          Content="Submit" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>Greeting is a DP in the code behind set to Hello World!</p>
  
  <p>I expect to reach a break point in Greeting or Text on text changed but I'm not.<br />
  Seems like the Two-way binding not working well.
  Anything different from WPF ? How can I make it work ?</p>