public
Created

This is how you can disable paste in TextBoxes in WPF

  • Download Gist
MainWindow.xaml
XML
1 2 3 4 5 6 7 8
<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>
MainWindow.xaml.cs
C#
1 2 3 4 5 6 7 8 9 10 11
public MainWindow()
{
InitializeComponent();
 
MyTextBox.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, Foo));
}
 
private void Foo(object sender, ExecutedRoutedEventArgs e)
{
e.Handled = true;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.