[英]DatePickerTextBox GotFocus event
如何从DatePickerTextBox
捕获GotFocus
事件,因此不会触发DatePicker
和DatePickerTextBox
GotFocus
和GotKeyboardFocus
事件。
GotFocus
event is internally handled by DatePicker
. GotFocus
事件由DatePicker
内部处理。 It by default changes e.Handled = true
for all GotFocus
RoutedEvents
which are triggered by its textbox. 默认情况下,它会更改由其文本框触发的所有
GotFocus
RoutedEvents
e.Handled = true
。
But DatePicker.GotKeyboardFocus
event is not effected by this. 但是
DatePicker.GotKeyboardFocus
事件不受此影响。 You can still listen to that event. 您仍然可以收听该事件。
In order to fire GotFocus
event, you'll have to explicitly add an event handler to listen to this it and change e.Handled
to false
. 为了触发
GotFocus
事件,您必须显式添加一个事件处理程序以侦听此事件,并将e.Handled
更改为false
。 ie: 即:
DatePicker1.AddHandler(DatePicker.GotFocusEvent, new RoutedEventHandler(DatePicker1_GotFocus), true);
void DatePicker1_GotFocus(object sender, RoutedEventArgs e)
{
e.Handled = false;
}
Update: 更新:
To open calendar upon focus use PreviewKeyDown
event: 要在焦点打开日历时使用
PreviewKeyDown
事件:
void DatePicker1_PreviewKeyDown(object sender, KeyEventArgs e)
{
var dp = sender as DatePicker;
if (e.Key == Key.Tab)
{
dp.IsDropDownOpen = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.