2

我们的 ListView 要求是列标题可以通过键盘访问,而默认 ListView 不会发生这种情况。例如:

    <StackPanel x:Name="LayoutRoot">
    <ListView HorizontalAlignment="Left" KeyboardNavigation.TabNavigation="Local">
        <ListView.View>
            <GridView >
                <GridViewColumn Header="Header _1" KeyboardNavigation.TabIndex="0"/>
                <GridViewColumn Header="Header _2" KeyboardNavigation.TabIndex="1"/>
                <GridViewColumn Header="header _3" KeyboardNavigation.TabIndex="2"/>
            </GridView>
        </ListView.View>
        <ListViewItem Content="I'm the first item" />
        <ListViewItem Content="I'm the second item" />
    </ListView>
    <Button Content="I can also get focus" HorizontalAlignment="Left" Margin="0,27,0,0"/>
</StackPanel>

访问键显示标题,但它们没有获得键盘焦点。我通过阅读此问题添加的 TabIndex 和 TabNavigation: tabbing to TextBoxes in column headers

我需要做什么才能使 GridViewColumnHeaders 键盘可访问?

4

1 回答 1

2

有人内部有解决方案。在 GridViewColumnHeader ControlTemplate 中,将 ContentPresenter 设置为 Focusable=true,如下所示:

            <ContentPresenter x:Name="ContentPresenter"
                Style="{StaticResource ListViewContentPresenterStyle}" 
                ContentTemplate="{TemplateBinding ContentTemplate}" 
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                RecognizesAccessKey="True"
                Focusable="True"
                Grid.Column="1">

此外,设置 ListView KeyboardNavigation.TabNavigation=Local。

于 2012-05-02T19:30:12.883 回答