AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.09k stars 2.26k forks source link

Intermittent Selector Failure Using PropertyEquals #11271

Open robloo opened 1 year ago

robloo commented 1 year ago

Describe the bug

To Reproduce

I'm merging the reproduction, expected behavior and screenshots sections together to make this easier to follow. There are a few different cases here.

Firstly, this was encountered with the #11264 PR so all repro should use that branch.

  1. Within ColorView (a normal control scenario) the following selectors are applied intermittently.

    <Style Selector="^ /template/ primitives|ColorSlider#Component1Slider[ColorModel=Rgba]">
      <Setter Property="IsPerceptive" Value="False" />
    </Style>
    <Style Selector="^ /template/ primitives|ColorSlider#Component2Slider[ColorModel=Rgba]">
      <Setter Property="IsPerceptive" Value="False" />
    </Style>
    <Style Selector="^ /template/ primitives|ColorSlider#Component3Slider[ColorModel=Rgba]">
      <Setter Property="IsPerceptive" Value="False" />
    </Style>

    https://user-images.githubusercontent.com/17993847/236684642-705d5651-e006-4933-942b-89545e7167ed.mp4

    Note that switching between Hsva and Rgba color models should apply/remove the style accordingly. This works sometimes but other times does not. There seems to be no clear pattern here. In the screen capture this is made visible by the slider gradient backgrounds changing color even with the same color model (clearest to see in RGB where if IsPerceptive=True the gradients will ONLY be red/green/blue).

  2. Within ColorPicker -- a control with the majority of its content hosted within a popup/flyout -- NONE of the selectors seem to be applied. This includes one more selector that works in ColorView.

    <Style Selector="^ /template/ primitives|ColorSlider#ColorSpectrumThirdComponentSlider[ColorComponent=Component1]">
      <Setter Property="IsPerceptive" Value="True" />
    </Style>
    
    <Style Selector="^ /template/ primitives|ColorSlider#Component1Slider[ColorModel=Rgba]">
      <Setter Property="IsPerceptive" Value="False" />
    </Style>
    <Style Selector="^ /template/ primitives|ColorSlider#Component2Slider[ColorModel=Rgba]">
      <Setter Property="IsPerceptive" Value="False" />
    </Style>
    <Style Selector="^ /template/ primitives|ColorSlider#Component3Slider[ColorModel=Rgba]">
      <Setter Property="IsPerceptive" Value="False" />
    </Style>

    https://user-images.githubusercontent.com/17993847/236684791-068b7b43-64f3-4992-af94-b6c6667b777f.mp4

    This is NOT intermittent and just always fails to apply the selectors within a popup/flyout. The RGB component sliders should not be red/green/blue (IsPerceptive=True) they should appear as the sliders in the ColorView visible before the popup/flyout is opened.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

robloo commented 1 year ago

I suppose it could be possible this has something to do with the async rendering or time it takes to generate the background gradient. Technically it is being calculated for two property changes very rapidly (ColorModel and IsPerceptive). It still feels like something is wrong with the property system but that's an alternative to investigate further.

maxkatz6 commented 1 year ago

I haven't been able to check this issue last week. Hopefully I will have time tomorrow, if nothing else will come up to work on.

maxkatz6 commented 1 year ago

I don't think it's something with async rendering, as even in dev tools IsPerceptive value is changing randomly. And set "Priority" is just lying there. I.e. it can say "LocalValue", when I removed local value from the ColorView.xaml and it could only be either Unset (=true by default) or set from style trigger (false). And style is not applied when it is expected to.

image

maxkatz6 commented 1 year ago

Added pseudoclasses to see if it helps to find a problem. Apparently there is something with dev tools or we got quantum mechanics observer effect. Selecting node in the dev tools tree changes its behavior.

https://github.com/AvaloniaUI/Avalonia/assets/3163374/56a25829-c822-4484-895b-276c6358f4b2

robloo commented 1 year ago

That's really strange, glad this is reproducible though. I'm away from a computer for the next few days but will be back to this shortly. Not sure how much I can help here though as it seems deep in the property and styling system.