Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Xwt.WPF/Xwt.WPFBackend/Util.cs')
-rw-r--r--Xwt.WPF/Xwt.WPFBackend/Util.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Xwt.WPF/Xwt.WPFBackend/Util.cs b/Xwt.WPF/Xwt.WPFBackend/Util.cs
index a678ba4d..0e9ca565 100644
--- a/Xwt.WPF/Xwt.WPFBackend/Util.cs
+++ b/Xwt.WPF/Xwt.WPFBackend/Util.cs
@@ -90,6 +90,21 @@ namespace Xwt.WPFBackend
return null;
}
+
+ /// <summary>
+ /// Get the the parent System.Windows.Window. If that fails for whatever reason (which can happen if the WPF
+ /// visual tree isn't rooted with a System.Windows.Window, like in the case where it's rooted in a WinForms
+ /// component), then fallback to returning the WPF MainWindow.
+ /// <param name="element">WPF element</param>
+ /// <returns>ancestor System.Windows.Window or MainWindow</returns>
+ public static System.Windows.Window GetParentOrMainWindow (this FrameworkElement element)
+ {
+ System.Windows.Window parentWindow = GetParentWindow (element);
+ if (parentWindow != null)
+ return parentWindow;
+
+ return System.Windows.Application.Current.MainWindow;
+ }
}
class XwtWin32Window : System.Windows.Forms.IWin32Window