如何从<div class="headRow">
</div>
<br>
<div class="divTable">
</div>
GotFocus
DatePickerTextBox
发现DatePicker
事件,DatePickerTextBox
GotFocus
和GotKeyboardFocus
事件无法触发。< / p>
答案 0 :(得分:0)
GotFocus
事件由DatePicker
内部处理。对于由其文本框触发的所有e.Handled = true
GotFocus
,默认情况下会更改RoutedEvents
。
但DatePicker.GotKeyboardFocus
事件不受此影响。你仍然可以听那个事件。
要发起GotFocus
事件,您必须明确添加事件处理程序以聆听此事件并将e.Handled
更改为false
。即:
DatePicker1.AddHandler(DatePicker.GotFocusEvent, new RoutedEventHandler(DatePicker1_GotFocus), true);
void DatePicker1_GotFocus(object sender, RoutedEventArgs e)
{
e.Handled = false;
}
<强>更新强>
要在焦点使用PreviewKeyDown
事件时打开日历:
void DatePicker1_PreviewKeyDown(object sender, KeyEventArgs e)
{
var dp = sender as DatePicker;
if (e.Key == Key.Tab)
{
dp.IsDropDownOpen = true;
}
}