How to properly ignore windows created by Visual Studio debugging tool for XAML

Viewed 647

In my application I need to get a list of all windows.

var windows = Application.Current.Windows;

If I run my application in debug mode I see not only my forms in the list, but also instances of Microsoft.XamlDiagnostics.WpfTap.WpfVisualTreeService.Adorners.AdornerLayerWindow created by Visual Studio debugging tool for XAML.

What is the right way to filter list of windows to ignore windows created by debugging tool? I don't want to reference additional assembly and check if

window is AdornerLayerWindow

and I don't want to filter like

window.GetType().Name != "AdornerLayerWindow"

Any other ideas?

1 Answers

I just do the trick window.ActualWidth != 0. It works good for me.

Application.Current.Windows
    .Cast<Window>()
    .Where(w => w.ActualWidth != 0)
    .ToList()
    .ForEach(w => w.Close());
Related