Created
September 16, 2023 08:10
-
-
Save Tocchann/4f0f9b0f059a13fa0ef1ec9c7cec9fb1 to your computer and use it in GitHub Desktop.
WPF でポップアップに渡すべきオーナーウィンドウにできる System.Windows.Window を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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