【发布时间】:2016-02-09 19:38:20
【问题描述】:
我创建了非常简单的布局来显示我的问题。基本上我在另一个用户控件(浏览)中有一个用户控件(表单),现在我希望能够使用 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>
谢谢你:)
【问题讨论】: