Elegantly override style of ComboBox's ToggleButton in WPF

后端 未结 2 1532
难免孤独
难免孤独 2021-02-19 06:13

I have a question regarding how to elegantly override an arbitrary element deep inside a control\'s visual tree. I also have attempted to resolve it in a few different ways, bu

2条回答
  •  甜味超标
    2021-02-19 06:37

    A Working Solution


    Hi, this style satisfies your needs, feel free to edit it as you need:

        
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        
        
    
    
    
    
        
            
                
                
            
            
                
                    
                    
                    
                    
                
            
            
            
            
        
        
            
                
                
                
                
            
            
                
                
                
                
            
            
                
                
                
            
            
                
                
                
                
            
        
    
    
    
        
    
    
    
    

    Note the DataTrigger part inside the toggle button style, it hooks to its templated parent's IsKeyboardFocusWithin property istead of IsFocused property, because the last one won't work if you set the ComboBox.IsEditable to True as I did in this style.

    
        
        
        
        
    
    

提交回复
热议问题