Treeview hide [+] [-] buttons

后端 未结 2 956
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 11:48

Does anyone know how to hide the [-] button for a treeview? The treeview will never be collapsed, and therefore I dont need the root node to have the collapse option. I know

2条回答
  •  猫巷女王i
    2021-01-07 12:15

    This should work. You need to modify the ControlTemplate of the TreeViewItem, the [+] / [-] button is actually a ToggleButton inside the TreeViewItem's ControlTemplate so all you need to do is set its visibility to hidden or collapsed.

    Create a project called "StackOverflowTests" (so you don't have to change anything) and paste this code in your Window1.xaml file. Should work right out of the box:

        
            
                
                    
                    
                    
                
                
                    
                    
                
                
                
                
                    
                
                
            
            
                
                
                
                    
                        
                            
                        
                    
                    
                        False
                    
                
                
                    
                        
                            
                        
                    
                    
                        
                            
                        
                    
                    
                        True
                    
                
                
                    
                        
                            
                                True
                            
                        
                        
                            
                                False
                            
                        
                    
                    
                        
                            
                        
                    
                    
                        
                            
                        
                    
                
                
                    
                        
                            
                        
                    
                    
                        False
                    
                
            
        
    
        
    
    
    
        
            
            
                
            
        
        
            
        
    
    

提交回复
热议问题