gpt4 book ai didi

wpf - DockPanel 选项卡顺序

转载 作者:行者123 更新时间:2023-12-03 14:37:03 24 4
gpt4 key购买 nike

我在 ItemsControl 的 DataTemplate 中设置了一个 DockPanel,如下所示:

<ItemsControl HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel>
<ComboBox DockPanel.Dock="Left"/>
<ComboBox DockPanel.Dock="Left"/>
<Button DockPanel.Dock="Right">Button</Button>
<!-- This will appear before the button...it has to go after it in the XAML so it will fill properly in the DockPanel -->
<TextBox DockPanel.Dock="Left" MinWidth="100" HorizontalAlignment="Stretch"/>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

我希望文本框填充组合框和按钮之间的所有剩余空间。我不得不将文本框放在 XAML 中的最后,因为 DockPanel 只会填充最后一个 child 。看起来不错;但是,标签顺序现在搞砸了。它现在选项卡组合框-组合框-按钮-文本框而不是组合框-组合框-文本框-按钮。

我尝试使用 KeyboardNavigation.TabIndex每个项目的属性,但由于这是 ItemsControl 的 DataTemplate (这些停靠面板中的每一个都将用于一个单独的项目),这使得选项卡顺序垂直向下跳到每个项目的组合框,然后垂直向下跳到每个文本框,然后垂直按下每个按钮,而不是遍历每一行,然后按下所需的行为。

示例用户界面:
[Combo11] [Combo12] [Text1] [Button1]
[Combo21] [Combo22] [Text2] [Button2]

在目前的情况下,它变为 Combo11,Combo12,Button1,Text1,Combo21,Combo22,Button2,Text2 .如果我添加 TabOrder 属性,它将变为 Combo11,Combo21,Combo12,Combo22,Text1,Text2,Button1,Button2 .

我想去 Combo11,Combo12,Text1,Button1,Combo21,Combo22,Text2,Button2 .

有人对如何解决这个 UI 问题有任何想法吗?

最佳答案

如果要保留 DockPanel,可以在父 DockPanel 上使用 KeyboardNavigation.TabNavigation="Local",然后可以在其中的控件上设置选项卡索引值。

像这样 -

    <ItemsControl HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel KeyboardNavigation.TabNavigation="Local">
<ComboBox DockPanel.Dock="Left" TabIndex="1"/>
<ComboBox DockPanel.Dock="Left" TabIndex="2"/>
<Button DockPanel.Dock="Right" TabIndex="4">Button</Button>
<!-- This will appear before the button...it has to go after it in the XAML so it will fill properly in the DockPanel -->
<TextBox DockPanel.Dock="Left" MinWidth="100" HorizontalAlignment="Stretch" TabIndex="3"/>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

如您所见,如果您只是设置控件的选项卡索引值,这些值对表单来说是全局的,因此首先将所有 TabIndex="0"插入,然后将所有 TabIndex="1"插入,依此类推。 Set KeyboardNavigation.TabNavigation="Local"在父容器上修复它。

关于wpf - DockPanel 选项卡顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3549678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com