title: WPF Usercontrol, TextBox PropertyChanged event not firing
body: <p>I have a usercontrol with a <code>DependencyProperty</code> of <code>Answer</code> which is attached to a <code>TextBox</code>.</p>
  
  <p>I have queried the database and bound the answer to the usercontrol and the correct value is displayed.</p>
  
  <p>The issue occurs when I edit the <code>TextBox</code>, the PropertyChanged event is not firing and thus preventing me from saving the correct value back to the database.
  Please see below my code.</p>
  
  <p><strong>Usercontrol:</strong></p>
  
  <pre><code>&lt;Grid&gt;
      &lt;StackPanel&gt;
              &lt;TextBlock Name="txtbQuestion" TextWrapping="Wrap"  Text="Question" Foreground="Black" Margin="5"  Style="{DynamicResource Label}" ToolTip="{Binding  RelativeSource={RelativeSource Self}, Path=Text}" &gt;&lt;/TextBlock&gt;
          &lt;Grid&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition /&gt;
                  &lt;ColumnDefinition  Width="100" /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;TextBox Name="txtAnswer" Margin="5" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" &gt;
                  &lt;TextBox.Style&gt;
                      &lt;Style&gt;
                          &lt;Style.Triggers&gt;
                              &lt;DataTrigger Binding="{Binding ElementName=cbMultiLine, Path=IsChecked}" Value="True"&gt;
                                  &lt;Setter Property="TextBox.TextWrapping" Value="Wrap" /&gt;
                                  &lt;Setter Property="TextBox.Height" Value="100" /&gt;
                                  &lt;Setter Property="TextBox.AcceptsReturn" Value="True" /&gt;
                              &lt;/DataTrigger&gt;
                          &lt;/Style.Triggers&gt;
                      &lt;/Style&gt;
                  &lt;/TextBox.Style&gt;
              &lt;/TextBox&gt;
              &lt;CheckBox Name="cbMultiLine" Content="MultiLine" Margin="5" FontFamily="Georgia" Grid.Column="1" /&gt;
          &lt;/Grid&gt;
          &lt;Line Fill="Black" Margin="4" /&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p><strong>Usercontrol.cs:</strong></p>
  
  <pre><code>public partial class ConditionQuestion : UserControl
  {
  
      public static readonly DependencyProperty AnswerProperty =
  DependencyProperty.Register("Answer", typeof(string), typeof(ConditionQuestion), new UIPropertyMetadata(null, Answer_PropertyChanged));
  
      public static readonly DependencyProperty QuestionProperty =
          DependencyProperty.Register("Question", typeof(string), typeof(ConditionQuestion), new UIPropertyMetadata(null, Question_PropertyChanged));
  
      public ConditionQuestion()
      {
          InitializeComponent();
      }
  
      public string Answer
      {
          get { return (string)GetValue(AnswerProperty); }
          set { SetValue(AnswerProperty, value); }
      }
  
      public string Question
      {
          get { return (string)GetValue(QuestionProperty); }
          set { SetValue(QuestionProperty, value); }
      }
  
      private static void Answer_PropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
      {
          ((ConditionQuestion)source).txtAnswer.Text = (string)e.NewValue;
      }
  
      private static void Question_PropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
      {
          ((ConditionQuestion)source).txtbQuestion.Text = (string)e.NewValue;
      }
  
  }
  </code></pre>
  
  <p><strong>Declaring instance of Usercontrol:</strong></p>
  
  <pre><code>&lt;ListBox ItemContainerStyle="{StaticResource noSelect}" ItemsSource="{Binding Answer}"
           Name="lbQuestions" BorderBrush="#E6E6E6" &gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;my:ConditionQuestion Question="{Binding ConditionReportFormQuestions.Question}"
                                    Answer="{Binding Answer, Mode=TwoWay,
                                             UpdateSourceTrigger=PropertyChanged}"  /&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>I apologize in advance, I am {relatively} new to WPF. Can anyone see where I may be going wrong with this?</p>
  
  <p>I have successfully got my other usercontrols binding and updating (this code is almost an exact copy) but the answers on them are <code>ListBox</code> selections where-as this usercontrol is binding to a <code>TextBox</code>.</p>
  
  <p>Thanks in advance,
  Kohan.</p>