【发布时间】:2017-06-14 07:49:18
【问题描述】:
我希望当用户按下向上/向下键在列表视图中移动时,即使认为列表视图不在焦点上。但是,如果用户在文本框中输入并向上按下不再在列表视图中导航。 可能的解决方案是为每个元素添加一个 PreviewKeyDown 事件,如果捕获的键是向上/向下的,则将其向下传递到树的下方,但这种解决方案似乎不太实用,因为我有很多元素。
示例代码:
<StackPanel>
<ListView x:Name="capturesUpDownWhenTextBoxNotFocused" ItemsSource="{Binding list}" ItemTemplate="{StaticResource template}">
<ListView.InputBindings>
<KeyBinding Key="Up" Command="{Binding upCommand}"></KeyBinding>
<KeyBinding Key="Down" Command="{Binding downCommand}"></KeyBinding>
</ListView.InputBindings>
</ListView>
<TextBox Text="random text"></TextBox>
<Button Content="button"></Button>
<ListView x:Name="doesNotCaptureUpDownEvenIfFocused" ItemsSource="{Binding activeFile.activeFilters}" ItemTemplate="{StaticResource template}"></ListView>
</StackPanel>
【问题讨论】:
标签: wpf keyboard-shortcuts lost-focus