WPF DataGridTemplateColumn. Am I missing something?

前端 未结 4 409
死守一世寂寞
死守一世寂寞 2021-01-12 20:19
     
        
            
                &l         


        
4条回答
  •  臣服心动
    2021-01-12 20:47

    My approach is to use a TriggerAction which sets the focus to the template element you want when it loads.

    The trigger is very simple:

    public class TakeFocusAndSelectTextOnVisibleBehavior : TriggerAction
    {
        protected override void Invoke(object parameter)
        {
            Dispatcher.BeginInvoke(
                DispatcherPriority.Loaded,
                new Action(() =>
                {
                    AssociatedObject.Focus();
                    AssociatedObject.SelectAll();
                }));
        }
    }
    

    The DataTemplate looks like this:

    
        
            
                
                    
                
            
        
    
    

    You can write other triggers for other element types.

提交回复
热议问题