Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avalonia Get All Windows

Is there a way to get a list of all windows in Avalonia?

The equivalent of this in WPF

Application.Current.Windows

My requirement is to activate or close a certain window based on its DataContext.

If I can't access such a list; is there a way to track the creation and destruction of windows to create an internal list?

like image 350
Etienne Charland Avatar asked Nov 16 '25 10:11

Etienne Charland


1 Answers

You need IClassicDesktopStyleApplicationLifetime::Windows property. Lifetime is available from Application's ApplicationLifetime property.

e. g.

((IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime).Windows

Note that it's not available for Mobile, WebAssembly and Linux framebuffer platforms.

like image 91
kekekeks Avatar answered Nov 17 '25 23:11

kekekeks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!