Skip to content

Instantly share code, notes, and snippets.

@Tocchann
Created September 16, 2023 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tocchann/4f0f9b0f059a13fa0ef1ec9c7cec9fb1 to your computer and use it in GitHub Desktop.
Save Tocchann/4f0f9b0f059a13fa0ef1ec9c7cec9fb1 to your computer and use it in GitHub Desktop.
WPF でポップアップに渡すべきオーナーウィンドウにできる System.Windows.Window を取得する
using System.Windows;
namespace Tocchann;
public static class Utilities
{
public static Window? GetOwnerWindow()
{
var window = default(Window);
foreach( Window search in Application.Current.Windows )
{
if( search.IsActive && search.Parent == null )
{
window = search;
break;
}
}
if( window == null )
{
window = Application.Current.MainWindow;
}
return window;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment