0

我正在尝试将标签索引设置为遵循视觉外观的顺序。这意味着出现在窗口顶部的按钮在我特别设置为不聚焦时首先获得焦点。

以下是控件的结构;

DocPanel
  |
  |---- DockPanel
  |       |----- Button
  |       |----- Button
  |       |----- Button
  |
  |---- Grid
          |----- Canvas
          |---- TabControl
                    |------ TextBox
                    |------ ComboBox

我想要的标签顺序;

  1. 帆布
  2. 文本框
  3. 组合框
  4. 3 个按钮

目前的订单是;

  1. 3 个按钮
  2. 文本框,
  3. 组合框
  4. 帆布。

我尝试设置KeyboardNavigation.TabNavigation="Local"外部 DockPanel。

然后我将TabNavigation.TabIndex和设置TabIndex为我想要的数字,但这不起作用。

如果控件出现在窗口的顶部,是否不能在控件出现在底部之后将标签索引更改为焦点?

这是我的 XAML:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    FocusManager.FocusedElement="{Binding ElementName=pic}"
    Title="Window1" Height="504" Width="929">
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" KeyboardNavigation.TabNavigation="Local">
    <DockPanel DockPanel.Dock="Top" Height="30">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="Save and Close" KeyboardNavigation.TabIndex="4" TabIndex="4"/>
            <Button Content="Forward" KeyboardNavigation.TabIndex="5" TabIndex="5" />
            <Button Content="Delete" KeyboardNavigation.TabIndex="6" TabIndex="6" />
        </StackPanel>
    </DockPanel>
    <Grid DockPanel.Dock="Bottom">
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="50"/>
            <ColumnDefinition MinWidth="500"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Border BorderBrush="Aqua" BorderThickness="2" >
            <Canvas x:Name="pic" Grid.Column="0" Grid.Row="0" KeyboardNavigation.TabIndex="1" KeyboardNavigation.IsTabStop="True" Focusable="True"  >
                <Canvas.Background>
                    <ImageBrush ImageSource="bookcover.jpg" Stretch="Fill"/>
                </Canvas.Background>
            </Canvas>
        </Border>
        <TabControl x:Name="tabs" Grid.Column="2" Grid.Row="0">
            <TabItem Header="Fax Details" IsTabStop="False">
                <StackPanel>
                <TextBox  Name="fdCustomerFileNumber" HorizontalAlignment="Left" Height="30" KeyboardNavigation.TabIndex="2" TabIndex="2" />

                <ComboBox TabIndex="3" KeyboardNavigation.TabIndex="3" Width="165"  HorizontalAlignment="Left" Height="22" VerticalAlignment="Center" Name="fdDocType" IsEditable="False" />
                </StackPanel>
            </TabItem>
        </TabControl>
    </Grid>

</DockPanel>

4

1 回答 1

0

您可以将 XAML 设置为;

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    FocusManager.FocusedElement="{Binding ElementName=pic}"
    Title="Window1" Height="504" Width="929">
    <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <DockPanel DockPanel.Dock="Top" Height="30">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Content="Save and Close" TabIndex="4"/>
                <Button Content="Forward" TabIndex="5" />
                <Button Content="Delete" TabIndex="6" />
            </StackPanel>
        </DockPanel>
        <Grid DockPanel.Dock="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="50"/>
                <ColumnDefinition MinWidth="500"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border BorderBrush="Aqua" BorderThickness="2" >
                <Canvas x:Name="pic" Grid.Column="0" Grid.Row="0" Focusable="True"  >
                    <Canvas.Background>
                        <ImageBrush ImageSource="bookcover.jpg" Stretch="Fill"/>
                    </Canvas.Background>
                </Canvas>
            </Border>
            <TabControl x:Name="tabs" Grid.Column="2" Grid.Row="0">
                <TabItem Header="Fax Details" IsTabStop="False">
                    <StackPanel>
                        <TextBox  Name="fdCustomerFileNumber" HorizontalAlignment="Left" Height="30" TabIndex="2" />
                        <ComboBox TabIndex="3" Width="165"  HorizontalAlignment="Left" Height="22" VerticalAlignment="Center" Name="fdDocType" IsEditable="False" />
                    </StackPanel>
                </TabItem>
            </TabControl>
        </Grid>
    </DockPanel>
</Window>

然后在你后面的代码中,在New Sub中,简单的把焦点设置到Canvas上;

pic.Focus;
于 2013-02-25T15:24:51.863 回答