Skip to content

Instantly share code, notes, and snippets.

@Tocchann
Created September 16, 2023 08:10
Show Gist options
  • 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