diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs index 8c97f12..626ea8f 100644 --- a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs +++ b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs @@ -114,6 +114,7 @@ public class MultiFormatTextBox : Control this.richTextBox.PreviewKeyDown += RichTextBox_KeyDown; this.richTextBox.PreviewTextInput += RichTextBox_PreviewTextInput; this.richTextBox.SelectionChanged += RichTextBox_SelectionChanged; + DataObject.AddPastingHandler(this.richTextBox, OnRtbPaste); } else { @@ -352,6 +353,24 @@ public class MultiFormatTextBox : Control this.InsertCharacterAtCaretPositionIntoCurrentMultiFormatString(e.Text); } + private void OnRtbPaste(object sender, DataObjectPastingEventArgs e) + { + // get pasted data + if (e.DataObject.GetDataPresent(typeof(string))) + { + // get data as string + var text = (string)e.DataObject.GetData(typeof(string)); + // insert each character seperately + foreach (var character in text) + { + this.InsertCharacterAtCaretPositionIntoCurrentMultiFormatString(character.ToString()); + } + } + + // cancel pasting + e.CancelCommand(); + } + private void InsertCharacterAtCaretPositionIntoCurrentMultiFormatString(string text) { var caretPosition = this.GetRtbCaretPosition();