Can a setter be used to return a property to its default value?

Think about whether this is possible, for example. if I delete the border from the TextBox, and I want to return it to the default when the mouse is over it.

<Style TargetType="TextBox"> <Setter Property="BorderBrush" Value="{x:Null}"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" Value="?????"/> </Trigger> </Style.Triggers> </Style> 

I thought I could use this, but in the end it seemed like a bad idea to hide the border, but the question remains. (I know that in this case I could flip the Trigger just to remove the border if the mouse is not above the TextBox)

+6
setter styles wpf wpf-controls
source share
1 answer

This is actually not the case. DependencyProperty works by looking at many different sources of value. And as you can see here , stylists and style triggers are considered separate sources. (They are numbered 8 and 6, respectively, in the "List of dependency property priority list" section.) Whatever of the sources of active values ​​with the highest priority.

Sources of sources of one kind cannot delete the value provided by another source. The only reason triggers can change a value based on what its setter sets is because triggers have a higher priority. It is not possible to eradicate the value provided by a source with a lower priority.

The way to achieve the specific goal that you have formulated here is to invert the meaning of the trigger - do not define the style installer and activate the trigger only when IsMouseOver is false. Of course, this will not help you in all possible cases when you want to do this. But since there is no general solution, I think you need to solve each specific problem in your own way.

+5
source share

All Articles