gpt4 book ai didi

wpf - 停止从一个用户控件跳出到另一个用户控件的键盘方向导航

转载 作者:行者123 更新时间:2023-12-04 16:14:33 27 4
gpt4 key购买 nike

我创建了非常简单的布局来显示我的问题。基本上我在另一个用户控件(浏览)中有一个用户控件(表单),现在我希望能够使用 tab 和 ctrl+tab 循环浏览表单,它确实如此。但我注意到,当我按下任何按钮(在表单内)上的箭头键时,它会跳出表单进行浏览。所以我将键盘的方向导航设置为无,但它忽略了它,仍然允许我使用箭头键导航。我如何确保我不能用键盘摆脱那种形式?

这是xaml

<Window xmlns:wpfApplication1="clr-namespace:WpfApplication1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Center" FontSize="36" Text="This is a browse" />
<wpfApplication1:Form Grid.Row="1"/>
<StackPanel Grid.Row="2"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button Height="50" Width="300">move previous</Button>
<Button Height="50" Width="300">move next</Button>
</StackPanel>
</Grid>
</Window>

<UserControl x:Class="WpfApplication1.Form"
Margin="30"
Background="Gray"
KeyboardNavigation.ControlTabNavigation="Cycle"
KeyboardNavigation.DirectionalNavigation="None"
KeyboardNavigation.TabNavigation="Cycle">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="First Name:" />
<TextBox Width="500"
Height="50"
HorizontalAlignment="Left" />
</StackPanel>
<StackPanel Grid.Row="1"
Grid.ColumnSpan="2"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button Width="200"
Height="50"
Content="Save" />
<Button Width="200"
Height="50"
Content="Close" />
</StackPanel>
</Grid>

谢谢 :)

最佳答案

来自 MSDN
KeyboardNavigationMode值(value)观:

None - No keyboard navigation is allowed inside this container.



这意味着不允许从该容器外部使用键导航到该容器中。

您正在寻找的是:

Contained - Depending on the direction of the navigation, focus returns to the first or the last item when the end or the beginning of the container is reached, but does not move past the beginning or end of the container.

关于wpf - 停止从一个用户控件跳出到另一个用户控件的键盘方向导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35287745/

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