Background does not change of button C# WPF

后端 未结 4 1356
一个人的身影
一个人的身影 2020-12-18 09:25

I am trying to change style on mouseover.

My Code is:

4条回答
  •  太阳男子
    2020-12-18 09:43

    In the default template of button, there is trigger in ControlTemplate which set Background of button to #FFBEE6FD and since control template triggers have higher precedence compared to Style triggers that's why your trigger never works.

    For that to achieve you have to override default template of button and remove that trigger from it so that your style trigger gets applied.

    Here is the default template with that specific trigger commented out. In case you want to override BorderBrush as well, get rid of it as well from the template.

    
        
            
        
        
            
                
                    
                        
                    
                
            
            
                
                
                    
                        #FF3C7FB1
                    
                
            
            
                
                    
                        #FFC4E5F6
                    
                
                
                    
                        #FF2C628B
                    
                
            
            
                
                    
                        #FFBCDDEE
                    
                
                
                    
                        #FF245A83
                    
                
            
            
                
                    
                        #FFF4F4F4
                    
                
                
                    
                        #FFADB2B5
                    
                
                
                    
                        #FF838383
                    
                
            
        
    
    

    How to set the control template to button?

    Define the template somewhere under resource section of parent panel or UserControl and can be applied via StaticResource:

    
       
          
           .......
       
       

提交回复
热议问题