Skip to content

Instantly share code, notes, and snippets.

@PaulStovell
Created March 8, 2011 23:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save PaulStovell/861384 to your computer and use it in GitHub Desktop.
This is how you can disable paste in TextBoxes in WPF
<Window x:Class="WpfApplication9.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox Name="MyTextBox" Text="Hello" />
</Grid>
</Window>
public MainWindow()
{
InitializeComponent();
MyTextBox.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, Foo));
}
private void Foo(object sender, ExecutedRoutedEventArgs e)
{
e.Handled = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment