简体   繁体   中英

Need to modfy the default tab order of child elements

I have custom control like below. When press tab key focus will move in the order elements arrangement.

Query:

When stackpanel receive tab focus I need to change default tab order toggle button present in stackpanel

Default Tab Order:

DockPanel--Border---StackPanel-->Button1-->button2-->button3

Expected Order

DockPanel--Border---StackPanel-->Button3-->button2-->button1

I need update TabOrder based on its parent. Please suggestion solution modify the tab order based on parent

Note: I need UI as like below arrangements, only i need to modify the tab order for buttons

<DockPanel VerticalAlignment="Center" HorizontalAlignment="Center">
            <Border x:Name="MainBorder">
                <StackPanel>
                    <ToggleButton>Button 1</ToggleButton>
                    <ToggleButton>Button 3</ToggleButton>
                    <ToggleButton>Button 3</ToggleButton>
                </StackPanel>
            </Border>
        </DockPanel>

As mentioned in comments do set the TabIndex property. To step within control do use KeyboardNavigation.TabNavigation attached property.

<DockPanel VerticalAlignment="Center" HorizontalAlignment="Center">
    <Border x:Name="MainBorder">
        <StackPanel KeyboardNavigation.TabNavigation="Local">
            <ToggleButton KeyboardNavigation.TabIndex="3">Button 1</ToggleButton>
            <ToggleButton KeyboardNavigation.TabIndex="2">Button 2</ToggleButton>
            <ToggleButton KeyboardNavigation.TabIndex="1">Button 3</ToggleButton>
        </StackPanel>
    </Border>
</DockPanel>

If you want to modify the tab order at run time I would advice you to create a behavior for it. See Use of Behavior in WPF MVVM? To access attached property from code see Get and set WPF custom attached property from code behind

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