WPF: Tab navigation broken with collapsed hyperlink

Problem: Navigation with the TAB key stops at collapsed TextBlock/Hyperlink.

Reproduction:

<Window x:Class="TabTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Width="200" Height="200">

    <Grid>
        <StackPanel Orientation="Vertical">
            <TextBox Text="before" />
            <TextBlock>
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Style>
                </TextBlock.Style>
                <Hyperlink Focusable="False">
                    <TextBlock Text="test" />
                </Hyperlink>
            </TextBlock>
            <TextBox Text="after" />
        </StackPanel>
    </Grid>
</Window>

If you run this super-simple demo and press TAB, the cursor moves to the "before" TextBox. Pressing TAB again does ... nothing. The cursor stays in the "before" TextBox and never reaches the "after" Textbox. Navigation works as expected when the Hyperlink's TextBlock is visible.

Question: How do I make TAB navigation work correctly with the HyperLink collapsed?

7
задан Helge Klein 28 March 2011 в 15:47
поделиться