Search code examples
c#avaloniauiavalonia

How to change a control style using a pseudo class like focus or pointerover in avalonia ui?


I've been searching for a way to change a control style when a pointer is over it or when it's in focus something like this

<Style Selector="TextBox:focus">
    <Setter Property="Background" Value="Red"/>
</Style> 

but for some reason nothing is happenning or changing

instead the TextBox background stayed in the same color


Solution

  • By referring to the Documentation Selector with a pseudoclass doesn't override the default

    The corrected code should target Border by using template selector

    <Style Selector="TextBox:focus /template/ Border">
      <Setter Property="Background" Value="Red"/>
    </Style>