首页 文章

在WPF ListBox中禁用键盘导航

提问于
浏览
1

如何在不使用鼠标禁用选择的情况下禁用WPF ListBox中的键盘导航?

1 回答

  • 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;
    }
    

相关问题