如何通过WPF中的键盘导航使ScrollViewer专注

时间:2019-05-17 16:39:53

标签: wpf xaml

我在键盘导航和ApplicationWindow { id: window visible: true width: 640 height: 480 property bool typelist : false ListModel{ id: listModel1 ListElement { test: "blue" } } ListModel{ id: listModel2 ListElement { test: "red" } ListElement { test: "blue" } } ListView { id: listView width: parent.width height: parent.height * 0.75 model: typelist ? listModel1 : listModel2 delegate: Rectangle{ width: parent.width height: 50 color: model.test } } Button { width: parent.width height: parent.heigth*0.25 anchors.bottom:parent.bottom onClicked: typelist=!typelist } } 方面遇到问题。这是我的设置:

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的顶级项目,我希望焦点会跳回到我的“清除”按钮,但是没有,它卡在ItemsControl中。我尝试了各种ItemsControls选项,但无济于事。

删除ScrollViewer可以修复导航,但这显然不可行,因为我需要显示更多适合屏幕的项目。

有什么想法吗?

0 个答案:

没有答案
相关问题