title: Two Way Binding to AvalonEdit Document Text using MVVM
body: <p>I want to include an AvalonEdit <code>TextEditor</code> control into my MVVM application. The first thing I require is to be able to bind to the <code>TextEditor.Text</code> property so that I can display text. To do this I have followed and example that was given in <a href="https://stackoverflow.com/questions/12344367/making-avalonedit-mvvm-compatible?lq=1">Making AvalonEdit MVVM compatible</a>. Now, I have implemented the following class using the accepted answer as a template </p>
  
  <pre><code>public sealed class MvvmTextEditor : TextEditor, INotifyPropertyChanged
  {
      public static readonly DependencyProperty TextProperty =
           DependencyProperty.Register("Text", typeof(string), typeof(MvvmTextEditor),
           new PropertyMetadata((obj, args) =&gt;
               {
                   MvvmTextEditor target = (MvvmTextEditor)obj;
                   target.Text = (string)args.NewValue;
               })
          );
  
      public new string Text
      {
          get { return base.Text; }
          set { base.Text = value; }
      }
  
      protected override void OnTextChanged(EventArgs e)
      {
          RaisePropertyChanged("Text");
          base.OnTextChanged(e);
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
      public void RaisePropertyChanged(string info)
      {
          if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(info));
      }
  }
  </code></pre>
  
  <p>Where the XAML is </p>
  
  <pre><code>&lt;Controls:MvvmTextEditor HorizontalAlignment="Stretch"
                           VerticalAlignment="Stretch"
                           FontFamily="Consolas"
                           FontSize="9pt" 
                           Margin="2,2" 
                           Text="{Binding Text, NotifyOnSourceUpdated=True, Mode=TwoWay}"/&gt;
  </code></pre>
  
  <p>Firstly, this does not work. The Binding is not shown in Snoop at all (not red, not anything, in fact I cannot even see the <code>Text</code> dependency property). </p>
  
  <p>I have seen this question which is exactly the same as mine <a href="https://stackoverflow.com/questions/14855304/two-way-binding-in-avalonedit-doesnt-work/14863468#comment27995064_14863468">Two-way binding in AvalonEdit doesn't work</a> but the accepted answer does <em>not</em> work (at least for me). So my question is: </p>
  
  <p><strong>How can I perform two way binding using the above method and what is the correct implementation of my <code>MvvmTextEditor</code> class?</strong></p>
  
  <p>Thanks for your time.</p>
  
  <hr>
  
  <p><em>Note: I have my <code>Text</code> property in my ViewModel and it implements the required <code>INotifyPropertyChanged</code> interface.</em></p>