简体   繁体   中英

WPF Tab Navigation In Children UserControl

I try to control my tab navigation. I made a little program to test it but i don't get what i want.

I want to tab in a certain order. And one of the tab focus on a user controle. Once i'm in a user controle i want to tab in another order. And then when all userControl Tab are done go back to my main control.

Because my code is really short i will paste it all.

First my 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>

Then the Page1 who are the userControl you see with TabIndex="3"

<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>

What i Get as Order when i Tab is

0 1 2 4 5 Child0 Child1 Child2 Child3

What i want is.

0 1 2 Child0 Child1 Child2 Child3 4 5

AnyWay to achieve this? I try to change TabNavigation to Local Container ect... And didn't find a way to make it work.

Remove KeyboardNavigation.TabNavigation="Contained" from the UserControl and try this:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM