wpf - 如何在 WPF 中使用键盘导航离开 ScrollViewer 的焦点
问题描述
我遇到了键盘导航和ScrollViewer
. 这是我的设置:
<DockPanel>
<Button DockPanel.Dock="Top" Content="Add" />
<Button DockPanel.Dock="Top" Content="Clear" />
<ItemsControl DockPanel.Dock="Top" Focusable="False"
ScrollViewer.CanContentScroll="True"
ItemsSource="{Binding ItemsList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Item.Name}"
IsChecked="{Binding Selected}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer Focusable="False">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
</DockPanel>
使用向上和向下箭头键移动焦点可以正常工作,直到焦点进入我的ItemsControls
. 然后我只能在里面移动焦点。例如,如果我到达 ItemsControls 的顶部项目,我希望焦点跳回我的“清除”按钮,但它没有,它卡在 ItemsControl 内。我尝试了各种KeyboardNavigation.DirectionalNavigation
选择,但没有任何效果。
删除 ScrollViewer 修复了导航,但这显然不可行,因为我需要显示更多适合屏幕的项目。
有任何想法吗?
解决方案
推荐阅读
- windows - 打开记事本并使用 .bat 文件写一些东西
- c# - c# System.Data.SqlClient.SqlException: macOS 中的 Snix_Connect
- r - 在使用 igraph 绘制网络时,如何根据特定的 actor 属性更改顶点颜色?
- c# - 如何在 xaml/mvvm 中启用/禁用 ffimageloading 转换?[Xamarin 形式]
- java - 如何使用 Selenium WebDriver 和 Java 将命令写入 Firefox 控制台?
- mysql - 如何根据列中的搜索在 MySQL 中设置 order by 优先级?
- css - 外部 Css 无法使用我的 HTML 代码,我的错误是什么?
- python - 用单个元素反转列表给出无
- c# - 如果时间是 00:00,如何在 Listview 上隐藏日期时间的时间
- asp.net-mvc - 从用户浏览器获取多语言网站的文化信息