如何在不使用鼠标禁用选择的情况下禁用WPF ListBox中的键盘导航?
答案 0 :(得分:6)
处理PreviewKeyDown
事件并将e.Handled
设置为true(您可以仅检查和禁用传递给处理程序的KeyEventArgs提供的某些键/修饰符):
XAML:
<ListBox PreviewKeyDown="listBox_PreviewKeyDown">
<ListBoxItem Content="asdfasdf" />
<ListBoxItem Content="asdfasdf" />
<ListBoxItem Content="asdfasdf" />
</ListBox>
代码背后:
private void listBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}