简体   繁体   中英

Find open Windows in XAML

I need a functionality to get all existing (open) instances of some conrete WPF window. I create those windows programatically in few places in code.

Is there a XAML/WPF solution for that? Something like GetInstancesByType(type) ?

You can use the Application.Windows property:

foreach( var window in Application.Current.Windows.OfType<MyType>() )
{
    // do stuff
}

As HB pointed out, you would need to include System.Linq to get the OfType<T> extension method, but it's not necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM