WPF DataGrid: how do I stop auto scrolling when a cell is clicked?

前端 未结 9 1148
旧巷少年郎
旧巷少年郎 2020-12-08 07:31

Problem:
If my DataGrid is not entirely visible (horizontal & vertical scrollbars are showing) and I click on one of my cells that is p

9条回答
  •  一个人的身影
    2020-12-08 07:44

    You can access the DataGrid's internal ScrollViewer by modifying the template. Although normally you wouldn't put an event handler to code behind in a template, if you declare the template inline you can treat the event handler the same way you are when you attach it to the DataGrid itself. This is the default template as generated from Blend including an added handler on the ScrollViewer for the RequestBringIntoView event:

    
    
        
            
                
                    
                        
                            
                            
                            
                        
                        
                            
                            
                            
                        
                        
                        
                            
                                
                                    
                                        Column
                                    
                                
                            
                        
                        
                        
                        
                            
                                
                                
                            
                            
                        
                    
                
            
            
        
    
    

提交回复
热议问题