开发者

Disabling keyboard navigation in WPF ListBox

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜