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
25.54k stars 2.21k forks source link

IsEffectivelyVisible should be a proper property just like IsEffectivelyEnabled is #15413

Open AlexeyTliss opened 6 months ago

AlexeyTliss commented 6 months ago

Is your feature request related to a problem? Please describe.

The problem is: control doesn't know when it becomes invisible due to it's parent IsVisible being changed to false. This causes me problem with two cases: 1) I tried to design a control which plays an animation when becomes visible. This worked fine if you manipulate IsVisible of the control itself, but broke if you change IsVisible of parent control 2) I deisgn an Ui Voice Control Engine and parse logical tree to search for controls which spawn content like ItemsControl and ContentControl, and subscribe to its events to know when their content is changed and I need to re-parse it. The problem is, if content is changed when control is not visible, the content is not actually spawned, and despite event being fired, I will load nothing by parsing them, until they becomes Visible, and I can't monitor their Visibility, unless it is directly controlled

Describe the solution you'd like

I would very much prefer IsEffectivelyVisible being an actualy property just like IsEffectivelyEnabled which can be monitored via PropertyChanged event

Describe alternatives you've considered

The current workaround is to subscribe to IsVisible change of every logical parent of control in tree, which is hacky and very unstabled solution for obvious reasons

Additional context

No response

grokys commented 6 months ago

I'd be hesitant to do this because of the performance overhead: the property change handler will have to be called for potentially the entire visual tree each time the property value changes, even if the property has no listeners (we don't know what people are doing in their OnPropertyChanged/PropertyChanged handlers so have to raise the event whether there are subscribers or not). Visiblility changes are a lot more common than enabled changes.

A potential alternative solution would be to add an EffectivelyVisibleChanged CLR event: this way we can explicitly tell when there are subscribers and avoid the overhead when there are none.