【发布时间】:2014-01-15 23:56:20
【问题描述】:
希望你能给我一个提示,我做错了什么。我认为实现我正在尝试的目标很容易,但我无法解决我的问题。
我想做什么?
我有一个包含几个控件的表单,例如左侧的文本框。在右侧,我确实有一个带有 TabItems 的 TabControl,并且在这些项目上也有几个,例如文本框。如果我打开表单,左侧的第一个 TextBox 将成为焦点。我以某种方式输入了 TabIndex,第一个 TabItem(可见)上的第一个 TextBox 应该在之后获得焦点。但是无论我输入什么,在第一个 TabItem 获得焦点之前,左侧的所有 TextBoxes 总是获得焦点。请在下面找到示例代码。我做错了什么?
<Grid Name="grid" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBox Name="tb1" TabIndex="0" Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox TabIndex="5" Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox TabIndex="1" Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
</StackPanel>
<TabControl Grid.Column="1" Height="Auto" Width="Auto" KeyboardNavigation.DirectionalNavigation="Contained">
<TabItem Header="1">
<StackPanel>
<TextBox TabIndex="4" Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox TabIndex="3" Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox TabIndex="6" Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox/>
</StackPanel>
</TabItem>
<TabItem Header="2">
<StackPanel>
<TextBox Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
<TextBox Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=TabIndex}"/>
</StackPanel>
</TabItem>
</TabControl>
</Grid>
非常感谢, 托斯滕
【问题讨论】:
-
这个问题你解决了吗?
标签: .net wpf tab-ordering