lighten background color on button click per binding with converter

前端 未结 3 490
夕颜
夕颜 2021-01-14 18:11

I want to lighten a buttons background on click. So I did the following:


3条回答
  •  悲&欢浪女
    2021-01-14 18:37

    You shouldn't be using System.Drawing.Color on WPF. Use System.Windows.Media.Color instead. Another important thing is that the Setters inside the ControlTemplate.Triggers do not have to reference the control by using RelativeSource TemplatedParent. Just:

    
        
    
    

    And keep the rest the same. Now, if you need to specify custom logic (such as a converter, just place the converter in that setter.

    Edit: The infinite loop comes from the fact that you're Binding to Background.Color, and then Setting Background, which triggers a Property Change notification into the WPF Property System, which in turn causes the Binding to be refreshed, and so on... I think you might be able to work around this by setting the binding Mode to = OneTime

提交回复
热议问题