我想在AutocompleteBox按下 CTRL+N 键时聚焦。我尝试了一些代码,但对我不起作用。在UserControl控制中,我使用PreviewKeyDown了如下事件,
注意:只有在MessageBox.Show("some");如下关键事件之前写入时,我才会使用以下代码获得焦点,
private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.N && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
MessageBox.Show("sfsd");
Keyboard.Focus(SearchTextBox);
SearchTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
e.Handled = true;
}
用户控件:
<UserControl x:Class="Inventory_Control.UserControls.SaleTab"
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"
xmlns:local="clr-namespace:Inventory_Control.UserControls"
xmlns:staticData="clr-namespace:Inventory_Control.UserControls"
mc:Ignorable="d"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
d:DesignHeight="450" d:DesignWidth="800" Loaded="UserControl_Loaded_1" PreviewKeyDown="UserControl_PreviewKeyDown"
>
上面的代码对我不起作用。请帮忙
HUH函数
相关分类