20 using System.Windows.Interop;
29 #region Public extension methods for Window 36 public static void SetOwnerForm(
this Window window, IntPtr ownerForm)
39 if (ownerForm != IntPtr.Zero)
41 WindowInteropHelper h =
new WindowInteropHelper(window);
53 window.SetOwnerForm(parentForm);
54 return window.ShowDialog();
58 Logger.Warn(
"ShowDialogInForm: Could not show dialog with owner form 0x{0:X08}; falling back to show dialog without owner",
61 window.SetOwnerForm(IntPtr.Zero);
62 return window.ShowDialog();
72 IntPtr mainWindowHandle = IntPtr.Zero;
79 Logger.Warn(
"ShowDialogInForm: Win32Window.MainWindowHandleProvider is not set!");
81 if (mainWindowHandle != IntPtr.Zero)
83 return window.ShowDialogInForm(mainWindowHandle);
87 Logger.Warn(
"ShowDialogInForm: No form handle, falling back to showing dialog outside of form!");
88 return window.ShowDialog();
95 public static void ShowInForm(
this Window window, IntPtr parentForm)
99 window.SetOwnerForm(parentForm);
104 Logger.Warn(
"ShowInForm: Could not show window with owner form 0x{0:X08}; falling back to show dialog without owner",
107 window.SetOwnerForm(IntPtr.Zero);
118 window.ShowInForm((
new Win32Window(window)).Handle);
125 private static NLog.Logger Logger {
get {
return _logger.Value; } }
127 private static readonly Lazy<
NLog.Logger> _logger =
new Lazy<
NLog.Logger>(() =>
NLog.LogManager.GetCurrentClassLogger());
static Func< IntPtr > MainWindowHandleProvider
Gets or sets a function that provides the global window handle of the main window of an application...
Provides access to the window handle of a WPF window or a Form or a custom handle.
Extension methods for the WPF Window class.
static void ShowInForm(this Window window, IntPtr parentForm)
Shows the Window as a dialog that belongs to a Windows form parent.
static void ShowInForm(this Window window)
Shows the Window as a dialog that belongs to a Windows form parent.
static bool ShowDialogInForm(this Window window, IntPtr parentForm)
Shows the Window as a dialog that belongs to a Windows form parent.
static void SetOwnerForm(this Window window, IntPtr ownerForm)
Make a Windows Form the Owner of a WPF Window.
static bool ShowDialogInForm(this Window window)
Shows the Window as a dialog that belongs to a Windows form parent.