I have a list view with drag and drop option to text box. I need to disable the ability to use CTRL+C or CTRL +X on the list box. I don't want it to be fired by the keyboard. Is there an option to prevent it in WPF?
<ListBox x:Name="Lst" IsSelected="False" Height="115" Width="150" ItemsSource="{Binding UsCollectionView}"
SelectionChanged="listbox_SelectionChanged" AllowDrop="True" PreviewDrop="ListBox_PreviewDrop"
</ListBox>
private void listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ListBox)
{
var listBox = sender as ListBox;
if (e.AddedItems.Count == 1)
{
if (listBox.SelectedItem != null)
{
var mySelectedItem = listBox.SelectedItem as User;
if (mySelectedItem != null)
{
DragDrop.DoDragDrop(listBox, mySelectedItem.Name, DragDropEffects.Copy | DragDropEffects.Move);
}
}
}
}
}
There are a number of way that you can do that. One way is to handle the
UIElement.PreviewKeyDown
Event, detect the relevant keys and then set thee.Handled
property totrue
: