diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
index 91e183d46d..a247af69cb 100644
--- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
+++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
@@ -75,17 +75,62 @@ namespace ICSharpCode.AvalonEdit
SetCurrentValue(OptionsProperty, textArea.Options);
SetCurrentValue(DocumentProperty, new TextDocument());
+
+ TextChanged += TextEditor_TextChanged;
}
-
- #if !DOTNET4
+
+ #region Make TextEditor MVVM-friendly
+
+ ///
+ /// Occurs when the text has changed.
+ ///
+ ///
+ ///
+ void TextEditor_TextChanged(object sender, EventArgs e)
+ {
+ DocumentText = Text;
+ }
+
+ ///
+ /// Gets or sets the DocumentText (set a Binding to this Property to support MVVM)
+ ///
+ public string DocumentText
+ {
+ get { return (string)GetValue(DocumentTextProperty); }
+ set { SetValue(DocumentTextProperty, value); }
+ }
+
+ ///
+ /// The dependency propety of the Document Text.
+ ///
+ public static readonly DependencyProperty DocumentTextProperty =
+ DependencyProperty.Register("DocumentText", typeof(string), typeof(TextEditor),
+ new PropertyMetadata(new PropertyChangedCallback(OnDocumentTextChanged)));
+
+ ///
+ /// Is called when the Text property has changed.
+ ///
+ ///
+ ///
+ private static void OnDocumentTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ TextEditor textEditor = d as TextEditor;
+ string documentText = e.NewValue as string;
+ if (textEditor.Text != documentText)
+ textEditor.Text = documentText;
+ }
+
+ #endregion
+
+#if !DOTNET4
void SetCurrentValue(DependencyProperty property, object value)
{
SetValue(property, value);
}
- #endif
- #endregion
-
- ///
+#endif
+ #endregion
+
+ ///
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new TextEditorAutomationPeer(this);