WPF autocompletebox和确认键 [英] WPF autocompletebox and the enter key
本文介绍了WPF autocompletebox和确认键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让WPF AutoCompleteBox当我preSS回车键提高KeyDown事件。我使用的是正常的KeyDown挂钩,这适用于一切,但回车键似乎。有谁知道我怎么能解决这个问题?
I am trying to get the WPF AutoCompleteBox to raise the KeyDown event when I press the enter key. I am using the normal KeyDown hook, which works for everything but the enter key it seems. Does anyone know how I can fix this?
推荐答案
您可以继承 AutoCompleteBox
,增加对<大骨节病>输入骨节病>事件。
You could inherit the AutoCompleteBox
, adding an event for Enter.
public class MyAutoCompleteBox : AutoCompleteBox
{
public override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if(e.Key == Key.Enter) RaiseEnterKeyDownEvent();
}
public event Action<object> EnterKeyDown;
private void RaiseEnterKeyDownEvent()
{
var handler = EnterKeyDown;
if(handler != null) handler(this);
}
}
在你的消费类,您可以订阅:
In your consuming class, you can subscribe:
public void Subscribe()
{
autoCompleteBox.EnterKeyDown += DoSomethingWhenEnterPressed;
}
public void DoSomethingWhenEnterPressed(object sender)
{
}
这篇关于WPF autocompletebox和确认键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文