DatePickerTextBox GotFocus事件

时间:2018-02-21 18:05:13

标签: c# wpf datepicker

如何从<div class="headRow"> </div> <br> <div class="divTable"> </div> GotFocus DatePickerTextBox发现DatePicker事件,DatePickerTextBox GotFocusGotKeyboardFocus事件无法触发。< / p>

1 个答案:

答案 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;
    }      
}