我搜索了堆栈溢出,然而,我无法找到任何解决方案。我认为问题来自定制控件或我做错了什么。我使用了一个名为" Dragablz"的自定义TabControl。每当我尝试使用' Tab'键盘上的键,它似乎继续TabItems,TabControl背景等。我想实现只通过当前选定的TabItem(按钮,组合框等)的网格内的控件进行导航。
这是代码
<Tool:DialogHost x:Name="RDialog" Loaded="OnRootDialog_Loaded" Identifier="RootDialog">
<Dock:Layout>
<Dbz:TabablzControl x:Name="TabControl" TextElement.Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=(TextElement.Foreground)}" Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Background}">
<TabItem Header="DEVICE" x:Name="tabItemDevice">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<ComboBox x:Name="cmbDevice" Width="300" FontSize="15" Tool:TextFieldAssist.Hint="Select Device:" SelectionChanged="OnDeviceComboBox_SelectionChanged"/>
<ComboBox x:Name="cmbAddress" Width="150" FontSize="15" Margin="30" Tool:TextFieldAssist.Hint="Select Address:" SelectionChanged="OnDeviceComboBox_SelectionChanged"/>
</StackPanel>
<Button x:Name="btnStartStop" Content="_START" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0 0 -4 -5" Click="OnDeviceButton_Click"/>
<Button x:Name="btnConfigureDevice" Content="_CONFIGURE DEVICE" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="-3 0 0 -5" Click="OnDeviceButton_Click"/>
</Grid>
</TabItem>
<TabItem Header="PHONEBOOK" x:Name="tabItemPhonebook">
<Grid>
<StackPanel Margin="-6" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button TabIndex="2" x:Name="btnNewClient" Content="_NEW CLIENT" VerticalAlignment="Bottom" HorizontalAlignment="Left" Click="OnPhonebookButton_Click"/>
<Button TabIndex="1" Margin="10 0 0 0" x:Name="btnOpenPhonebook" Content="_OPEN PHONEBOOK" VerticalAlignment="Bottom" HorizontalAlignment="Left" Click="OnPhonebookButton_Click"/>
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="MANAGE CALLS" x:Name="tabItemManageCall">
<Grid>
<StackPanel Margin="-6" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button TabIndex="3" x:Name="btnCallRecord" Content="_CALL RECORDS" VerticalAlignment="Bottom" HorizontalAlignment="Right" Click="OnManageCallsButton_Click"/>
<Button TabIndex="4" x:Name="btnDial" Margin="10 0 0 0" Content="_DIAL" VerticalAlignment="Bottom" HorizontalAlignment="Right" Click="OnManageCallsButton_Click"/>
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="SETTINGS" x:Name="tabItemSetting">
<Grid>
<StackPanel Margin="-6" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button x:Name="btnApplicationSetting" Content="APPLICATION SETTINGS"/>
<Button x:Name="btnContactMe" Content="CONTACT ME" Margin="10 0 0 0" Click="OnSettingsButton_Click"/>
</StackPanel>
</Grid>
</TabItem>
</Dbz:TabablzControl>
</Dock:Layout>
</Tool:DialogHost>
我尝试过使用以下内容; KeyboardNavigation.TabNavigation="Cycle" KeyboardNavigation.IsTabStop="False"
不幸的是,它没有工作,它仍然通过标签项,我只想在TabItem控件内导航。
谢谢!
解决方法我成功了;
private void OnMainWindow_KeyDown(object Sender, KeyEventArgs e)
{
if(e.Key == Key.Tab)
{
e.Handled = true;
if (TabControl.SelectedIndex == 0) /* Device */
{
if(!cmbDevice.IsFocused || !cmbAddress.IsFocused
|| btnConfigureDevice.IsFocused || btnStartStop.IsFocused)
{
cmbDevice.Focus();
}
else if (cmbDevice.IsFocused)
{
cmbAddress.Focus();
}
else if (cmbAddress.IsFocused)
{
btnConfigureDevice.Focus();
}
else if (btnConfigureDevice.IsFocused)
{
btnStartStop.Focus();
}
else if (btnStartStop.IsFocused)
{
cmbDevice.Focus();
}
}
}
}