windowswindows-8.1windows-8.1-universal

How can I block Pasting a Text into TextBox in windows store app?


We need to disable the pasting option in TextBox of XAML page. Because we are working on question and answers type for that we need to disable the pasting option.


Solution

  • I would recommend against disabling copy/paste. Disabling those options in text fields serves little more than annoying the user.

    However, if you are to prevent Ctrl+C / Ctrl+V combinations, you could use

    1. The KeyDown event - if you get that combination you could, for example, clear the clipboard with the static method Windows.ApplicationModel.DataTransfer.Clipboard.Clear();
    2. not tested: ShortcutsEnabled property or Paste method, if they are available for the textbox in your project type, might be enough.

    EDIT: Make sure you disable the right click on your textbox as well.