Wondering if that is possible, e.g. if i remove the border from a TextBox and i want to have its default border back 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 that 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 reverse the Trigger to only remove the border if the mouse is not over the TextBox)
It doesn't really work like that. The DependencyProperty system works by considering numerous different value sources. And as you can see here, style setters and style triggers are considered to be separate sources. (They're numbered 8 and 6 respectively in the "Dependency Property Setting Precedence List" section.) Whichever of the active value sources has the highest priority wins.
Property sources of one kind cannot remove the value provided by a different source. The only reason triggers are able to change the value from what a setter sets it to is that triggers have a higher priority. There's no power to eradicate a value supplied by a lower-priority source.
The way to achieve the particular goal you've expressed here would be to invert the sense of the trigger - don't define a style setter, and make the trigger active only when IsMouseOver
is false. Of course, that won't help you in all the possible cases where you might want to do this. But since there isn't a general solution, I think you'd need to solve each specific problem in its own way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With