Seems pseudoclass selector is not working.
See original GitHub issueDescribe the bug
The style with selector :focus
and :focus-within
is not working properly.
To Reproduce Here is my test xaml code:
<Style Selector="Grid">
<Setter Property="Opacity" Value="0.1"></Setter>
</Style>
<Style Selector="Grid:focus">
<Setter Property="Opacity" Value="0.5"></Setter>
</Style>
<Style Selector="Grid:focus-within">
<Setter Property="Opacity" Value="1"></Setter>
</Style>
The opacity won’t change once the control gets neither :focus
nor :focus-within
.
I acknowledged the style below would override the style above and tried to change the order, but it still not works.
Expected behavior The opacity would change.
Desktop (please complete the following information):
- OS: Windows 11
- Version 22H2
Additional context I’ve already checked https://github.com/AvaloniaUI/Avalonia/pull/2662#issuecomment-515764732 https://github.com/AvaloniaUI/Avalonia/issues/5406 https://docs.avaloniaui.net/docs/styling/troubleshooting#selector-with-a-pseudoclass-doesnt-override-the-default . I found grid does not have a template in fluent, so those solutions above are not applying to this situation.
Issue Analytics
- State:
- Created 9 months ago
- Comments:5
Top GitHub Comments
@sht2017 It’s a bit janky with
Opacity
, but you can combine anot
selector here and that might be sufficient for you. Docs for selectorsThanks for your help. I tried it and found out what was wrong with my code. Actually,
Grid
withoutBackground
is okay. Here was my source code before:The issue was if you set a property in control, it would override the style. Then I removed the property
Opacity
inGrid
, and it works fine.