【发布时间】:2014-01-13 08:22:24
【问题描述】:
我有一个带有拖放选项到文本框的列表视图。 我需要禁用在列表框中使用 CTRL+C 或 CTRL +X 的功能。 我不希望它被键盘触发。在 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);
}
}
}
}
}
【问题讨论】: