using System.Windows; namespace OpenTapEditor.UI { public class MvvmTextEditor : ICSharpCode.AvalonEdit.TextEditor { public static readonly DependencyProperty DocumentTextProperty = DependencyProperty.Register( "DocumentText", typeof(string), typeof(MvvmTextEditor), new FrameworkPropertyMetadata( string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDocumentTextChanged)); public string DocumentText { get { return (string)GetValue(DocumentTextProperty); } set { SetValue(DocumentTextProperty, value); } } private static void OnDocumentTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is MvvmTextEditor editor) { if (editor.Document != null && editor.Document.Text != (string)e.NewValue) { editor.Document.Text = (string)e.NewValue ?? string.Empty; } } } protected override void OnTextChanged(EventArgs e) { SetCurrentValue(DocumentTextProperty, base.Text); base.OnTextChanged(e); } } }