<i id='DxG4a'><tr id='DxG4a'><dt id='DxG4a'><q id='DxG4a'><span id='DxG4a'><b id='DxG4a'><form id='DxG4a'><ins id='DxG4a'></ins><ul id='DxG4a'></ul><sub id='DxG4a'></sub></form><legend id='DxG4a'></legend><bdo id='DxG4a'><pre id='DxG4a'><center id='DxG4a'></center></pre></bdo></b><th id='DxG4a'></th></span></q></dt></tr></i><div id='DxG4a'><tfoot id='DxG4a'></tfoot><dl id='DxG4a'><fieldset id='DxG4a'></fieldset></dl></div>

<tfoot id='DxG4a'></tfoot>
<legend id='DxG4a'><style id='DxG4a'><dir id='DxG4a'><q id='DxG4a'></q></dir></style></legend>

      <bdo id='DxG4a'></bdo><ul id='DxG4a'></ul>

    1. <small id='DxG4a'></small><noframes id='DxG4a'>

    2. WPF 选项卡键导航

      时间:2023-08-28

        <tbody id='gjUqW'></tbody>
        <bdo id='gjUqW'></bdo><ul id='gjUqW'></ul>
        <i id='gjUqW'><tr id='gjUqW'><dt id='gjUqW'><q id='gjUqW'><span id='gjUqW'><b id='gjUqW'><form id='gjUqW'><ins id='gjUqW'></ins><ul id='gjUqW'></ul><sub id='gjUqW'></sub></form><legend id='gjUqW'></legend><bdo id='gjUqW'><pre id='gjUqW'><center id='gjUqW'></center></pre></bdo></b><th id='gjUqW'></th></span></q></dt></tr></i><div id='gjUqW'><tfoot id='gjUqW'></tfoot><dl id='gjUqW'><fieldset id='gjUqW'></fieldset></dl></div>

          • <tfoot id='gjUqW'></tfoot>
            • <legend id='gjUqW'><style id='gjUqW'><dir id='gjUqW'><q id='gjUqW'></q></dir></style></legend>
            • <small id='gjUqW'></small><noframes id='gjUqW'>

                本文介绍了WPF 选项卡键导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我们有一个基于 WPF .NET 4.0 C# 的应用程序.我们从 XML 定义(不是 XAML)构建我们的用户界面,但在下面我们使用 WPF 来呈现 UI.也就是说,在运行时,我们基于 XML 定义创建 WPF UI.

                We have a WPF .NET 4.0 C# based application. We built our user interface from XML definitions (not XAML) but underneath we use a WPF to present the UI. That is at runtime, we create the WPF UI based on our XML definition.

                标签导航有问题.我们为文本和组合框控件设置了 TabStop、TabIndex.
                但是标签导航不起作用.如何使标签导航适用于此布局?

                We have a problem with tab navigation. We set TabStop, TabIndex, for text and combo box controls.
                But tab navigation is not working. How to make tab navigation work for this layout?

                推荐答案

                WPF 将整个 UI 树视为单个 Tab 范围.它不会像您期望的那样分解成更小的区域.这包括 UserControls 中的控件.

                WPF treats the entire UI Tree as a single Tab scope. It isn't broken up into smaller areas such as you would expect. This includes controls inside UserControls.

                例如,如果你有

                <StackPanel>
                    <TextBox Name="TextBox1" />
                    <MyUserControl />
                    <TextBox Name="TextBox3" />
                </StackPanel>
                

                MyUserControl 看起来像

                <MyUserControl>
                    <TextBox Name="TextBox2"  />
                </MyUserControl>
                

                默认选项卡循环为 TextBox1、TextBox2、TextBox3.这是因为没有定义 TabIndex 属性,所以所有控件都以默认的 Tab 键顺序运行,也就是它们添加到 UI 中的顺序.

                The default tab cycle would be TextBox1, TextBox2, TextBox3. This is because no TabIndex properties are defined, so all controls run at the default tab order, which is the order in which they're added to the UI.

                如果您在控件上设置 TabIndex,如下所示,

                If you set the TabIndex on your controls such as below,

                <StackPanel>
                    <TextBox Name="TextBox1" TabIndex="1" />
                    <MyUserControl TabIndex="2" />
                    <TextBox Name="TextBox3" TabIndex="3" />
                </StackPanel>
                

                您的制表符将更改为 TextBox1、TextBox3、TextBox2.这是因为 TextBox2 没有指定 TabIndex,因此假定为默认值,并且在所有其他指定了 TabIndex 的控件循环通过之后,它会被选项卡化.

                Your tabbing would change to TextBox1, TextBox3, TextBox2. This is because TextBox2 doesn't have a TabIndex specified, so the default is assumed and it is tabbed to after all the other controls with a TabIndex specified get cycled through.

                我通常解决这个问题的方法是将 UserControl 内控件的 TabIndex 绑定到 UserControl.TabIndex.

                The way I usually get around this is to bind the TabIndex of controls inside the UserControl to the UserControl.TabIndex.

                例如,将以下绑定添加到 UserControl 将使 Tab 循环再次正确

                For example adding the following binding to the UserControl would make the Tab cycle correct again

                <MyUserControl>
                    <TextBox Name="TextBox2" TabIndex="{Binding Path=TabIndex, RelativeSource={RelativeSource AncestorType={x:Type local:MyUserControl}}}" />
                </MyUserControl>
                

                我通常更喜欢在 UserControl 的 Loaded 事件中设置此绑定,而不必记住在 UserControl 内的所有控件上设置此绑定.我相信还有更有效的方法可以做到这一点,但是问题出现的频率还不够高,让我坐下来花时间研究如何正确使用选项卡范围以避免这种解决方法.

                I usually prefer to set this binding in the Loaded event of the UserControl instead of having to remember to set this binding on all the controls inside the UserControl. I'm sure there are also more efficient ways of doing this as well, however the problem has not come up often enough for me to sit down and take the time to research how to use tab scopes correctly to avoid this workaround.

                这篇关于WPF 选项卡键导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:处理返回导航 Windows 10 (UWP) 下一篇:为 Windows Phone 8.1 在页面之间传递数据

                相关文章

                最新文章

                <legend id='NL037'><style id='NL037'><dir id='NL037'><q id='NL037'></q></dir></style></legend>

                <small id='NL037'></small><noframes id='NL037'>

                  <bdo id='NL037'></bdo><ul id='NL037'></ul>
                  <i id='NL037'><tr id='NL037'><dt id='NL037'><q id='NL037'><span id='NL037'><b id='NL037'><form id='NL037'><ins id='NL037'></ins><ul id='NL037'></ul><sub id='NL037'></sub></form><legend id='NL037'></legend><bdo id='NL037'><pre id='NL037'><center id='NL037'></center></pre></bdo></b><th id='NL037'></th></span></q></dt></tr></i><div id='NL037'><tfoot id='NL037'></tfoot><dl id='NL037'><fieldset id='NL037'></fieldset></dl></div>
                  1. <tfoot id='NL037'></tfoot>