开发者

Disabling keyboard navigation in WPF ListBox

开发者 https://www.devze.com 2023-02-03 01:47 出处:网络
How do I disable keyb开发者_StackOverflow社区oard navigation in a WPF ListBox without disabling selection using the mouse?Handle the PreviewKeyDown event to and set e.Handled to true (you could check

How do I disable keyb开发者_StackOverflow社区oard navigation in a WPF ListBox without disabling selection using the mouse?


Handle the PreviewKeyDown event to and set e.Handled to true (you could check and disable only certain keys/modifiers which are provided with the KeyEventArgs passed to the handler):

XAML:

<ListBox PreviewKeyDown="listBox_PreviewKeyDown">
  <ListBoxItem Content="asdfasdf" />
  <ListBoxItem Content="asdfasdf" />
  <ListBoxItem Content="asdfasdf" />
</ListBox>

Code behind:

private void listBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
  e.Handled = true;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消