WPF: complex tab focus behavior
My control is constructed from nested list boxes and tree views. Each list box / tree view item also contains rich text boxes and other controls.
I 开发者_如何学运维want to define a 'tab' focus behavior such that when the user clicks 'Tab' the next focusable item (according to an order i define) will become focused.
Currently it doesn't work as i accept (it only works partially).
My question is not specific to my case - rather on how to define such behavior at all. As an extreme example, let's say i want to completely control this and make the focus jump between items not physically near.
Anyone might know how this can be controlled?
Joe, this mechanism is smarter than i thought, check this nesting - it works perfectly:
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBoxItem Focusable="False">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBox.Items>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="1" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="2" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="3" Focusable="True"/>
</ListBoxItem>
</ListBox.Items>
</ListBox>
</ListBoxItem>
<ListBoxItem Focusable="False">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBox.Items>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="1" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<StackPanel>
<TextBox Width="300" KeyboardNavigation.TabIndex="3" Focusable="True"/>
<Border BorderBrush="Red">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBoxItem Focusable="False">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBox.Items>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="1" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="2" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="3" Focusable="True"/>
</ListBoxItem>
</ListBox.Items>
</ListBox>
</ListBoxItem>
<ListBoxItem Focusable="False">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBox.Items>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="1" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="2" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="3" Focusable="True"/>
</ListBoxItem>
</ListBox.Items>
</ListBox>
</ListBoxItem>
</ListBox>
</Border>
</StackPanel>
</ListBoxItem>
<ListBoxItem Focusable="False">
<StackPanel>
<TextBox Width="300" KeyboardNavigation.TabIndex="3" Focusable="True"/>
<Border BorderBrush="Red">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBoxItem Focusable="False">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBox.Items>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="1" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="2" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="3" Focusable="True"/>
</ListBoxItem>
</ListBox.Items>
</ListBox>
</ListBoxItem>
<ListBoxItem Focusable="False">
<ListBox KeyboardNavigation.TabNavigation="Continue">
<ListBox.Items>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="1" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="2" Focusable="True"/>
</ListBoxItem>
<ListBoxItem Focusable="False">
<TextBox Width="300" KeyboardNavigation.TabIndex="3" Focusable="True"/>
</ListBoxItem>
</ListBox.Items>
</ListBox>
</ListBoxItem>
</ListBox>
</Border>
</StackPanel>
</ListBoxItem>
</ListBox.Items>
</ListBox>
</ListBoxItem>
</ListBox>
Are you looking for the KeyboardNavigation.TabIndex property?
精彩评论