我有一个WPF用户控件,其XAML在这里给出。
<UserControl x:Class="Trial.WpfControls.OrganisationPicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Height="25" Width="200">
<DockPanel HorizontalAlignment="Stretch" Name="dockPanel1" VerticalAlignment="Stretch">
<TextBox Name="txtOrgId" TabIndex="101" Width="168" Height="Auto" Keyboard.PreviewKeyDown="txtOrgId_PreviewKeyDown" LostFocus="txtOrgId_LostFocus" />
<Button Content="Search" TabIndex="102" Name="btnOrgSearchSelector" Width="32" Height="Auto" DockPanel.Dock="Right" Click="btnOrgSearchSelector_Click" Keyboard.PreviewKeyDown="btnOrgSearchSelector_PreviewKeyDown" />
</DockPanel>
</Grid>
</UserControl>
当我把它放在其他WPF窗口并将TAB放到此控件上时,在窗口上进行选项卡时,不知怎的,这个控件不会失去焦点。焦点出现在“搜索”按钮上并且仅保留在那里。
如何解决此问题?为什么不释放焦点?
更新:
当我将KeyboardNavigation.TabNavigation="Once"
添加到UserControl
元素时,焦点会超出控件范围。但是当我从文本框中选择TAB时,它直接熄灭而不是将焦点设置在“搜索”按钮上。所以这对我来说当然不是预期的行为。