【问题标题】:WPF Tabindexes not behaving as expected - The force is weakWPF Tabindexes 未按预期运行 - 力量较弱
【发布时间】:2010-10-15 18:02:22
【问题描述】:

我有一个带有各种控件的 WPF 窗口/表单。

我已将 tabindexes 设置为所需的顺序,但出现了奇怪的行为。

在窗口中切换时,顺序应该如下:首先是左侧的文本框,然后是右侧的日期控件,然后是我的选项卡控件和选项卡页,然后只有按钮。

但选项卡控件被跳过,焦点直接移到按钮上。如果我在按钮之后继续使用选项卡,则会选择选项卡控件。

下面是xmal。

感谢任何帮助。

    <Window xmlns:my="clr-namespace:DevExpress.Xpf.Editors;assembly=DevExpress.Xpf.Core.v10.1"  x:Class="TabStopIssue.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
  xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        Title="MainWindow" Height="350" Width="525">
  <Grid>
    <Grid >
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>
      <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="2*"/>
          <ColumnDefinition Width="2*"/>
          <ColumnDefinition Width="3*" />
          <ColumnDefinition Width="3*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition />
          <RowDefinition />
          <RowDefinition />
          <RowDefinition />
        </Grid.RowDefinitions>


        <Label Grid.Row="1" Grid.Column="0" Content="Name"/>
        <dxe:ComboBoxEdit Grid.Row="1" Grid.Column="1"  Text="" TabIndex="0" />

        <Label Grid.Row="2" Grid.Column="0" Content="Description"/>
        <dxe:TextEdit Grid.Row="2" Grid.Column="1" TabIndex="1" />

        <Label Grid.Row="1" Grid.Column="2" Content="From Date"/>
        <dxe:DateEdit Grid.Row="1" Grid.Column="3" TabIndex="2" />

        <Label Grid.Row="2" Grid.Column="2" Content="ToDate"/>
        <dxe:DateEdit Grid.Row="2" Grid.Column="3" TabIndex="3" />
      </Grid>
      <Grid Grid.Row="1">
        <TabControl TabIndex="4">
          <TabItem Header="Tab1" TabIndex="5">
            <Grid >
              <TextBox>Enter Text Here</TextBox>
            </Grid>
          </TabItem>

          <TabItem Header="Tab2" TabIndex="6">
            <Grid >
              <TextBox>Enter Text Here</TextBox>
            </Grid>
          </TabItem>

          <TabItem Header="tab3" TabIndex="7">
            <Grid >
              <TextBox>Enter Text Here</TextBox>
            </Grid>
          </TabItem>

          <TabItem Header="tab4" TabIndex="8">
            <Grid >
              <TextBox>Enter Text Here</TextBox>
            </Grid>
          </TabItem>

          <TabItem Header="tab5" TabIndex="9">
            <Grid >
              <TextBox>Enter Text Here</TextBox>
            </Grid>
          </TabItem>
        </TabControl>
      </Grid>
      <Grid Grid.Row="2">
        <StackPanel HorizontalAlignment="Right">
          <Button  Content="Button1" IsDefault="True" TabIndex="10" />
          <Button  Content="Button2" TabIndex="11" />
          <Button Content="button3" IsCancel="True" TabIndex="12" />
        </StackPanel>
      </Grid>
    </Grid>
  </Grid>
</Window>

【问题讨论】:

    标签: wpf user-interface wpf-controls focus


    【解决方案1】:

    要让 TabControl 出现在 Tab 键顺序中的正确位置,请修改 TabControl 元素,如下所示:

    <TabControl TabIndex="4" KeyboardNavigation.TabNavigation="Local">
    

    据我所知,您不能使用 tab 键在 TabControl 上的各个选项卡之间切换。标准的 Windows 行为是为此使用箭头键。

    【讨论】:

    • 嗨塞缪尔,感谢您的帮助。像魅力一样工作。
    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    相关资源
    最近更新 更多