WPF trigger doesn't work

前端 未结 1 1323
温柔的废话
温柔的废话 2021-01-16 01:08

I want to change my Button Background, Margin, and Foreground when the mouse hovers, But It changes only the foreground. Please help..



        
1条回答
  •  遥遥无期
    2021-01-16 01:27

    If a property is set in an attribute, as you've done with Margin and Background, that overrides anything the Style does, so a Style trigger can't change it.

    Set the default values for those properties in Setters in the Style, but not in the Style.Triggers section. And take off the Margin and Background properties you have on it now.

    As Clemens notes in a comment, this behavior is explained by the rules for Dependency Property Value Precedence. It's better this way: Usually you want attributes to override the style, and only in this trigger case would you ever want the style to override anything else.

    
    

    Vaguely Off-Topic Ranting

    Personally, as a user of software, I find it very frustrating to have controls move when I click them, which is the effect your trigger will have when it changes the margin. Just yesterday I sent feedback to a website about that very issue. I told them that using their page felt like poking an angry raccoon with a stick.

    But as a developer, that's your call. Their interface was much more egregious than yours, to be honest. It was full of swirly purple stuff. I had to ask them if Google Analytics tracked how many viewers committed suicide. I doubt they'll reply. Customer service is a lost art.

    0 讨论(0)
提交回复
热议问题