我正在尝试使用 KeyboardAccelerators 更改 PivotControl 中的页面。我使用了文档中的代码:
<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)。是否有任何需要覆盖的本机行为?谢谢您的帮助。