我尝试控制标签导航。我做了一个小程序来测试它,但我没有得到想要的东西。
我想按特定顺序进行切换。选项卡之一集中在用户控件上。一旦我处于用户控制之下,我想以另一种顺序切换。然后,当所有userControl选项卡完成后,返回到我的主控件。
因为我的代码很短,所以我将其全部粘贴。
首先是我的mainWindow。
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel KeyboardNavigation.TabNavigation="Local">
<TextBox Text="0" KeyboardNavigation.TabIndex="0" />
<TextBox Text="5" KeyboardNavigation.TabIndex="5" />
<local:Page1 KeyboardNavigation.TabIndex="3"/>
<TextBox Text="4" KeyboardNavigation.TabIndex="4" />
<TextBox Text="1" KeyboardNavigation.TabIndex="1" />
<TextBox Text="2" KeyboardNavigation.TabIndex="1" />
</StackPanel>
</Window>
然后是使用TabIndex =“ 3”看到的userControl的Page1
<UserControl x:Class="WpfApp1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel KeyboardNavigation.TabNavigation="Contained">
<TextBox Text="Child 0" KeyboardNavigation.TabIndex="0" />
<TextBox Text="Child 1" KeyboardNavigation.TabIndex="1" />
<TextBox Text="Child 3" KeyboardNavigation.TabIndex="3" />
<TextBox Text="Child 2" KeyboardNavigation.TabIndex="2" />
</StackPanel>
</UserControl>
当我使用Tab键时,我得到的定单
0 1 2 4 5 Child0 Child1 Child2 Child3
我想要的是
0 1 2小孩0小孩1小孩2小孩3 4 5
有什么办法实现这一目标?我尝试将TabNavigation更改为Local Container ect ...,但没有找到一种使之工作的方法。
答案 0 :(得分:1)
从KeyboardNavigation.TabNavigation="Contained"
中删除UserControl
,然后尝试以下操作:
<StackPanel>
<TextBox Text="0" KeyboardNavigation.TabIndex="0" />
<TextBox Text="5" KeyboardNavigation.TabIndex="5" />
<local:Page1 KeyboardNavigation.TabIndex="3" KeyboardNavigation.TabNavigation="Local"/>
<TextBox Text="4" KeyboardNavigation.TabIndex="4" />
<TextBox Text="1" KeyboardNavigation.TabIndex="1" />
<TextBox Text="2" KeyboardNavigation.TabIndex="2" />
</StackPanel>