使用 Contrl+(Shift)+Tab 在 Pivot Control 中循环 tabs/headers? (UWP)
Use Contrl+(Shift)+Tab to cycle through tabs/headers in Pivot Control? (UWP)
我正在尝试使用 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)。是否有任何需要覆盖的本机行为?感谢您的帮助。
The problem is that neither accelerator is invoked. I can see in the live property viewer that Ctrl+Tab is registered
这是因为 Ctrl+Tab 是常见 UWP 控件的默认键盘行为。如果您没有为 Pivot 控件添加任何键盘加速器,那么,您按 Ctrl+Tab,它仍然会在 PivitItems 之间切换。如果将其更改为 Ctrl+Z,则会触发 Invoked
事件。
我正在尝试使用 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)。是否有任何需要覆盖的本机行为?感谢您的帮助。
The problem is that neither accelerator is invoked. I can see in the live property viewer that Ctrl+Tab is registered
这是因为 Ctrl+Tab 是常见 UWP 控件的默认键盘行为。如果您没有为 Pivot 控件添加任何键盘加速器,那么,您按 Ctrl+Tab,它仍然会在 PivitItems 之间切换。如果将其更改为 Ctrl+Z,则会触发 Invoked
事件。