是否使用Contrl+(Shift)+Tab在数据透视控件中循环浏览选项卡/页眉?(UWP)



我正在尝试使用KeyboardAccelerators更改数据透视控件中的页面。我使用了文档中的代码:

<Pivot x:Name="rootPivot" Title="PIVOT TITLE">
<Pivot.RightHeader>
<CommandBar ClosedDisplayMode="Compact">
<AppBarButton Icon="Back" Label="Previous" Click="BackButton_Click"/>
<AppBarButton Icon="Forward" Label="Next" Click="NextButton_Click"/>
</CommandBar>
</Pivot.RightHeader>
<PivotItem Header="Pivot Item 1">
<!--Pivot content goes here-->
<TextBlock Text="Content of pivot item 1."/>
</PivotItem>
<PivotItem Header="Pivot Item 2">
<!--Pivot content goes here-->
<TextBlock Text="Content of pivot item 2."/>
</PivotItem>
<PivotItem Header="Pivot Item 3">
<!--Pivot content goes here-->
<TextBlock Text="Content of pivot item 3."/>
</PivotItem>
</Pivot>

和代码背后:

public MainPage() {
InitializeComponent();
KeyboardAccelerator goRight = new KeyboardAccelerator() {
ScopeOwner = rootPivot,
Modifiers = Windows.System.VirtualKeyModifiers.Control,
Key = Windows.System.VirtualKey.Tab
};
goRight.Invoked += (s, e) => {
e.Handled = true;
int index = rootPivot.SelectedIndex;
index += 1;
index %= rootPivot.Items.Count;
rootPivot.SelectedIndex = index < 0 ? index + rootPivot.Items.Count : index;
};
rootPivot.KeyboardAccelerators.Add(goRight);
KeyboardAccelerator goLeft = new KeyboardAccelerator() {
ScopeOwner = rootPivot,
Modifiers = Windows.System.VirtualKeyModifiers.Control | Windows.System.VirtualKeyModifiers.Shift,
Key = Windows.System.VirtualKey.Tab
};
goLeft.Invoked += (s, e) => {
e.Handled = true;
int index = rootPivot.SelectedIndex;
index -= 1;
index %= rootPivot.Items.Count;
rootPivot.SelectedIndex = index < 0 ? index + rootPivot.Items.Count : index;
};
rootPivot.KeyboardAccelerators.Add(goLeft);
}

问题是两个加速器都没有被调用。我可以在实时属性查看器中看到Ctrl+Tab已注册(找不到Ctrl+Shift+Tab(。是否有任何本地行为需要重写?谢谢你的帮助。

问题是两个加速器都没有被调用。我可以在实时属性查看器中看到Ctrl+Tab已注册

这是因为Ctrl+选项卡是常见UWP控件的默认键盘行为。如果您没有为Pivot控件添加任何键盘快捷键,然后按Ctrl+选项卡,它仍然会在PivitItems之间切换。如果将其更改为Ctrl+Z,则会触发Invoked事件。

最新更新