// Check if the Add New Download window is already open public static bool IsWindowAlreadyOpen(Type WindowType) { foreach (Window OpenWindow in Application.Current.Windows) { if (OpenWindow.GetType() == WindowType) { return(true); } } return(false); }
/// <summary>Tries to return a previously-initialised window of type <typeparamref name="T"/>.</summary> /// <typeparam name="T"></typeparam> /// <param name="App">The application.</param> /// <param name="Found">The found <see cref="Window"/> (of type <typeparamref name="T"/>).</param> /// <returns><see cref="bool"/></returns> public static bool TryGetWindow <T>(this Application App, out T Found) where T : Window { // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (Window OpenWindow in App.Windows) { if (OpenWindow.GetType() == typeof(T)) { Found = (T)OpenWindow; return(true); } } Found = null; return(false); }