DataGridTemplateColumn with DatePicker requires three clicks to edit the date

前端 未结 2 497
轻奢々
轻奢々 2021-01-05 22:17

I have a DataGridTemplateColumn. Inside its CellEditingTemplate, I put a DatePicker control. Now if I want to edit the date, I have to

2条回答
  •  长发绾君心
    2021-01-05 22:47

    You have to override the PrepareCellForEdit in DataGridTemplateColumn as follows:

    public class DataGridDateColumn:DataGridTemplateColumn
    {
        protected override object PrepareCellForEdit(FrameworkElement editingElement,
                                                     RoutedEventArgs editingEventArgs)
        {
            editingElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
            return base.PrepareCellForEdit(editingElement, editingEventArgs);
        } 
    }
    

    XAML

    
        
            
            
    
            
                
                    
                        
                    
                
                
                    
                               
                    
                
            
        
    
    

提交回复
热议问题