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;
}
精彩评论