WPF Restrict pasting text in a textbox

By [)ia6l0 iii

Use the DataObject's Pasting handler to avoid pasting text into a textbox


XAML:
<TextBox x:Name="PasteRestrictedTextBox" DataObject.Pasting="PasteRestrictedTextBox_Pasting" />

CODE:
private void PasteRestrictedTextBox_Pasting(object sender, DataObjectPastingEventArgs e)
{
       e.CancelCommand();
}

Related FAQs

Use the DataObject's Copying handler to avoid copying text from a textbox
WPF Restrict pasting text in a textbox  (1488 Views)