WPF: Trigger for ListBoxItem.IsSelected not working for Background property

前端 未结 4 1132
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 02:17

I try to change the Background property for my ListBoxItems using triggers in the ItemContainerStyle of my ListBox as fol

4条回答
  •  旧时难觅i
    2020-12-31 02:45

    A little bit of reflecting on the Aero-style offers us an explanation to why this simple trigger-setting doesn't work.

    The ListBoxItem has a ControlTemplate with triggers that takes precedence over our trigger. At least this seems to be true for a MultiTrigger. I´ve managed to override the simple trigger of Selected=true but for the multitrigger I had to make my own ControlTemplate.

    This is the template from the Aero style that shows the problematic MultiTrigger:

    
        
            
                
                
            
            
                
                    
                    
                
                
                
            
            
                
            
        
        
            
        
    
    

    Hope it clears things up a little bit. I can't fathom why they´ve overcomplicated the style this much.

提交回复
热议问题