In my WPF 4.0 desktop-based application, I want to add an ability to traverse through window elements by pressing Tab-button.
Here is fragment of my XAML:
<!--main body layout-->
<StackPanel x:Name="BodyLayout"
Style="{StaticResource Body_Block}">
<!--teaser block-->
<Grid x:Name="TeaserGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0"
Grid.Row="0"
Style="{StaticResource Body_Teaser_Centering}">
<Hyperlink Style="{StaticResource Body_Teaser_Hyperlink}"
Focusable="True"
KeyboardNavigation.TabIndex="0"
Click="Call_WinOffences_Click">
<Image Source="Resources/teaser_offences.png"
Style="{StaticResource Body_Teaser_Image}" />
<LineBreak />
<TextBlock Text="Offences"
Style="{StaticResource Body_Title}" />
</Hyperlink>
</TextBlock>
<TextBlock Grid.Column="1"
Grid.Row="0"
Style="{StaticResource Body_Teaser_Centering}">
<Hyperlink Style="{StaticResource Body_Teaser_Hyperlink}"
Focusable="True"
KeyboardNavigation.TabIndex="1"
Click="Call_WinEvents_Click">
<Image Source="Resources/teaser_events.png"
Style="{StaticResource Body_Teaser_Image}" />
<LineBreak />
<TextBlock Text="Events"
Style="{StaticResource Body_Title}" />
</Hyperlink>
</TextBlock>
</Grid>
</StackPanel>
What exactly do I need?
I want to open this window and by pressing first time on Tab keyboard to set focus on Hyperlink block (with Image
and TextBlock
) with TabIndex="0"
and by second Tab pressing to switch focus on element with TabIndex="1"
, also I want to cycle this switches. In other words, I want that user could navigate through elements in my window by Tab keyboard as we are regular to do this in any other normal WinForms application.
What actually have I right now? When I press on Tab keyboard Hyperlinks don't get focus and I can't work with my window without the mouse.
Please, let me know, what am I doing wrong?