microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.36k stars 678 forks source link

Collapsed/Expanded Event for Expander Control #5495

Open amdingler opened 3 years ago

amdingler commented 3 years ago

Proposal: Collapsed/Expanded Event for Expander Control

Summary

It would be great to be able to access an event to perform an action once the Expander control has completely collapsed or expanded.

Rationale

Important Notes

The current Collapsed event is misnamed, and it is fired as soon as the expander begins collapsing.

michael-hawker commented 3 years ago

Thought this was resolved in https://github.com/microsoft/microsoft-ui-xaml/pull/4394

I think this is basically a duplicate of https://github.com/microsoft/microsoft-ui-xaml/issues/4407

robloo commented 3 years ago

I think @amdingler is also focusing on naming and the timing of events here. This was all discussed:

  1. Explanation for current event naming
  2. Discussion about event timing related to animations

To fire events after the animation itself is complete is no simple task. It also would heavily restrict the template itself.

There was also a request to make the events "symmetrical" and have all four: Collapsing, Collapsed, Expanding, Expanded. Bug: Expander Events Naming #4390

robloo commented 3 years ago

The current Collapsed event is misnamed, and it is fired as soon as the expander begins collapsing.

The code fires the event AFTER the visual state is applied here. In-code sequence is correct and was double checked.

The concern about animation continuing after collapsed is fired was noted as mentioned in the above comment. However, there is no correct fix for this. Can you name any other control that waits for an animation which is part of the style to complete before it fires a fundamental event? I don't believe even AnimatedVisualPlayer or AnimatedIcon have such events. In fact doing so breaks the lookless control concept of separation between logic and style. Logic starts to depend directly on style and the code-behind has to get pretty invasive to manage things correctly. Restyling is very difficult at that point.

If it is very important for your app, I do believe the animation times are fixed. You could add a delay of N milliseconds after receiving the Collapsed event to be sure the animation is complete.

Edit: I double checked WPF which also appears to behave the same way.

mrlacey commented 3 years ago

Note that if adding a delay on the assumption that there will be animations, need to allow for animations being disabled in the system-wide accessibility settings

StephenLPeters commented 3 years ago

@ranjeshj FYI