简体   繁体   中英

How to tab once instead of twice in WPF

I have a simple page that allows me to associate names with bunks. Unfortunately tab isn't working as I expect. I have to tab once to get to the next item and again to get to the TextBox. This also occurs if I remove the Label control. I've searched and searched and tried a bunch of things but can't figure this one out. Any suggestions? I'm starting to get comfortable with WPF MVVM but I'm no expert.

<Page x:Class="DiverBoard.Views.ConfigurePage"
      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:vm="clr-namespace:DiverBoard.ViewModels"
      mc:Ignorable="d" 
      d:DesignHeight="400" d:DesignWidth="800"
      Title="ConfigurePage" Background="Navy">
    <Page.DataContext>
        <vm:TripViewModel/>
    </Page.DataContext>
    <WrapPanel>
        <ListBox Background="Navy" ItemsSource="{Binding Trip.Bunks}" KeyboardNavigation.TabNavigation="Cycle">
            <ListBox.Template>
                <ControlTemplate>
                    <DockPanel LastChildFill="True">
                        <ItemsPresenter></ItemsPresenter>
                    </DockPanel>
                </ControlTemplate>
            </ListBox.Template>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Label FontSize="18" Foreground="white" Content="{Binding Value.BunkNumber}" Width="50"></Label>
                        <TextBox FontSize="18" Text="{Binding Value.DiverName}" Width="200" IsTabStop="true"></TextBox>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </WrapPanel>
</Page>

开始,选项卡,选项卡

Naturally I figured it out right after posting a question by reading something again that I had already read.

    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="IsTabStop" Value="False"/>
        </Style>
    </ListBox.ItemContainerStyle>

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