WPF Focus Navigation Wrapping

Is there a way to make Focus Navigation (controlled by the Tab key or MoveFocus) wrap inside this container? I have included code that demonstrates this problem below. The easiest way to make a Tab to move focus from TextBox“Charlie” to TextBox“Able” (and vice versa for Shift + Tab to TextBox“Able”), and not move it to MenuItem“Alpha”?

<Window x:Class="NavWrapExample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <DockPanel LastChildFill="True">
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="Alpha" />
            <MenuItem Header="Bravo" />
            <MenuItem Header="Charlie" />
        </Menu>
        <StackPanel>
            <TextBox Text="Able" />
            <TextBox Text="Baker" />
            <TextBox Text="Charlie" />
        </StackPanel>
    </DockPanel>
</Window>
+3
source share
2 answers

Use the Ke property yboardNavigation.TabNavigation , for example:

<StackPanel KeyboardNavigation.TabNavigation="Cycle">
    <TextBox Text="Able" />
    <TextBox Text="Baker" />
    <TextBox Text="Charlie" />
</StackPanel>

Found the answer to Mark Smith's blog .

+4

, , , : , , . , FocusManager :

<StackPanel FocusManager.IsFocusScope="True">
    <!-- Controls go here... -->
</StackPanel>
-1

Source: https://habr.com/ru/post/1715113/


All Articles