我找到了这个related question,它似乎(大部分)用于DataGridTextColumn中的TextBox。
如何为CellEditingTemplate中具有DatePicker的DataGridTemplateColumn实现类似的行为?
这段代码似乎无休止地被调用,这表明我们正在尝试将焦点设置为错误的元素:
private void DatePickerLostFocusHandler(object sender, RoutedEventArgs routedEventArgs)
{
// What is the correct property to use here?
// datePicker.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(datePicker))
{
// Looks like this is setting focus to wrong element -- it ends up getting called repeatedly.
var element = (sender as DatePicker);
var restoreFocus = (System.Threading.ThreadStart)delegate { element.Focus(); };
Dispatcher.BeginInvoke(restoreFocus);
}
}
感谢您的任何见解---