Shift + Tab键不TreeView控件工作 [英] Shift+Tab not working in TreeView control

查看:116
本文介绍了Shift + Tab键不TreeView控件工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用Shift + Tab键在包含TextBoxs一个TreeView工作得到向后导航,使用Tab键前进导航工作正常,从跳跃到文本框的文本框里面的TreeView。任何时候换挡时在TreeView里面的文本框之一,然后将焦点转移到TreeView外先前的控制,而不是树视图里面的一个控件+ Tab键使用。

I cannot get backwards navigation using Shift+Tab to work in a TreeView that contains TextBoxs, forward navigation using Tab works fine and jump from TextBox to TextBox inside the TreeView. Anytime Shift+Tab is used when one of the TextBoxes inside the TreeView, then the focus is move to the previous control outside the TreeView, instead of the previous control inside the TreeView.

也是其唯一的SHIFT +未正常工作标签导航,按Ctrl +预期和Shift + Tab键的工作以正确的顺序。

Also its only Shift+Tab navigation that are not working correctly, Ctrl+Shift+Tab work as expected and in the correct order.

要什么我任何建议?m做错了

Any suggestions to what I'm doing wrong?

示例代码:

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

<Window.Resources>
    <Style TargetType="TreeViewItem">
        <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue" />
    </Style>
</Window.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <TextBox Text="First Line" Grid.Row="0" />

    <TreeView Grid.Row="1" KeyboardNavigation.TabNavigation="Continue" IsTabStop="False">           
        <TreeViewItem IsExpanded="True"><TreeViewItem.Header><TextBox Text="Popular Words"/></TreeViewItem.Header>
            <TreeViewItem><TreeViewItem.Header><TextBox Text="Foo"/></TreeViewItem.Header></TreeViewItem>
            <TreeViewItem><TreeViewItem.Header><TextBox Text="Bar"/></TreeViewItem.Header></TreeViewItem>
            <TreeViewItem><TreeViewItem.Header><TextBox Text="Hello"/></TreeViewItem.Header></TreeViewItem>
        </TreeViewItem>
        <TreeViewItem IsExpanded="True"><TreeViewItem.Header><TextBox Text="Unpopular Words"/></TreeViewItem.Header>
            <TreeViewItem><TreeViewItem.Header><TextBox Text="Work"/></TreeViewItem.Header></TreeViewItem>
            <TreeViewItem><TreeViewItem.Header><TextBox Text="Duplication"/></TreeViewItem.Header></TreeViewItem>
        </TreeViewItem>
    </TreeView>

    <TextBox Text="Last Line" Grid.Row="2" />
</Grid>



推荐答案

如果您使用ILSpy /反射的TreeView.OnKeyDown处理程序看,你可以看到你的问题的原因。在TreeView有当按下Shift + Tab键进行特殊处理。相关的代码是:

If you look in the TreeView.OnKeyDown handler using ILSpy/Reflector, you can see the cause of your issues. The TreeView has special handling when Shift+Tab is pressed. The relevant code is:

Key key = e.Key;
if (key != Key.Tab) {
    // ... 
}
else {
    if (TreeView.IsShiftKeyDown && base.IsKeyboardFocusWithin &&
        this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous))) {
        e.Handled = true;
        return;
    }
}



不幸的是,你需要使用自定义的TreeView类以解决这个问题。像这样工作的:

Unfortunately, you'd need to use a custom TreeView class to work around this. Something like this works:

public class MyTreeView : TreeView {
    protected override void OnKeyDown(KeyEventArgs e) {
        if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0 && e.Key == Key.Tab)
            return;

        base.OnKeyDown(e);
    }
}

这篇关于Shift + Tab键不TreeView控件工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆