Restore previous value as a result of trigger

2019-08-28 23:10发布

问题:

If i'm using ControlTemplate.Triggers that used by <Trigger Property="IsMouseOver" Value="True">
How can I restore the previous value in case that IsMouseOver will be false?

(For example change background to green on IsMouseOver=true and revert to previous color before change. The previous color can be set on the control himself and not necessarily inside of the style)

Facets:

  1. I'm using stoaryboard in the trigger
  2. In the control style I set the background to Blue
  3. In the implementation of the window with the control i'm setting the control to the style but set the background of the control to Red.
  4. I want to set animation that will change it from red to green and when IsMouseOver=false revert it to red again.

Please Help Me!

回答1:

Triggers do not permanently change the value, they can be active and inactive, if they are inactive you automatically get the previous value (according to rules of precedence).

Template triggers will not override local values, so you have to use a setter for the default.

As you use an animation that will override all other things, you can animate it back via the Trigger.ExitActions, but you will need to know the original value for that.