Reputation: 1705
How do I disable keyboard navigation in a WPF ListBox without disabling selection using the mouse?
Upvotes: 2
Views: 5237
Reputation: 104781
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;
}
Upvotes: 8