예제 #1
0
        public static void HandleShowMessageWindow(IntPtr owner, Window window)
        {
            OwnerWindow = owner;
            WindowOperation.SetParent(new WindowInteropHelper(window).Handle, owner);
            WindowOperation.ShowWindow(new WindowInteropHelper(window).Handle, 1);
            var windowHelper = new WindowInteropHelper(window)
            {
                Owner = owner
            };

            window.Closing -= Window_Closing;
            window.Closing += Window_Closing;
            window.Show();
        }
예제 #2
0
        public static void HandleShowDialogWindow(IntPtr owner, Window window, bool isWindowShow = false, Action <IDialogResult> action = null)
        {
            if (owner != null && owner.ToInt32() != 1)
            {
                OwnerWindow = owner;
            }
            if (!isWindowShow)
            {
                foreach (var item in Application.Current.Windows.OfType <Window>())
                {
                    if (item.GetType().Name == "AdornerWindow")
                    {
                        continue;
                    }
                    if (item.IsLoaded && item.IsVisible && PresentationSource.FromVisual(item) != null)
                    {
                        return;
                    }
                }
            }

            var targetWindow = Application.Current.Windows.OfType <Window>().FirstOrDefault(m => m.GetType() == window.GetType());

            if (targetWindow != null)
            {
                WindowOperation.SetParent(new WindowInteropHelper(window).Handle, owner);
                WindowOperation.ShowWindow(new WindowInteropHelper(window).Handle, 1);
                var windowHelper = new WindowInteropHelper(targetWindow)
                {
                    Owner = OwnerWindow
                };
                targetWindow.Closing -= TargetWindow_Closing;
                targetWindow.Closing += TargetWindow_Closing;
                targetWindow.ShowDialog();
                if (targetWindow.DataContext is IDialogResult dialog)
                {
                    action?.Invoke(dialog);
                }
                else
                {
                    action?.Invoke(null);
                }
            }
        }
예제 #3
0
 private static void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     _mainWindow = null;
     WindowOperation.SetForegroundWindow(OwnerWindow);
 }