fix: Added parent window for modal dialog

This commit is contained in:
SlimeNull
2023-02-17 10:40:04 +08:00
parent bddd6f3f57
commit 6e3cd4bb42
5 changed files with 36 additions and 5 deletions

View File

@@ -68,7 +68,9 @@ namespace ClashN.Handler
FilterIndex = 2, FilterIndex = 2,
RestoreDirectory = true RestoreDirectory = true
}; };
if (fileDialog.ShowDialog() != DialogResult.OK)
IWin32Window parent = App.Current.MainWindow.WpfWindow2WinFormWin32Window();
if (fileDialog.ShowDialog(parent) != DialogResult.OK)
{ {
return; return;
} }

View File

@@ -28,7 +28,7 @@ using ZXing.Windows.Compatibility;
namespace ClashN namespace ClashN
{ {
class Utils static class Utils
{ {
#region Json操作 #region Json操作
@@ -1274,5 +1274,21 @@ namespace ClashN
public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attribute, ref int attributeValue, uint attributeSize); public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attribute, ref int attributeValue, uint attributeSize);
#endregion #endregion
public static System.Windows.Forms.IWin32Window WpfWindow2WinFormWin32Window(this System.Windows.Window wpfWindow)
{
return new WinFormWin32WindowWrapper(
new System.Windows.Interop.WindowInteropHelper(wpfWindow).Handle);
}
private class WinFormWin32WindowWrapper : System.Windows.Forms.IWin32Window
{
public WinFormWin32WindowWrapper(IntPtr hwnd)
{
Handle = hwnd;
}
public IntPtr Handle { get; }
}
} }
} }

View File

@@ -117,7 +117,9 @@ namespace ClashN.ViewModels
Multiselect = false, Multiselect = false,
Filter = "YAML|*.yaml;*.yml|All|*.*" Filter = "YAML|*.yaml;*.yml|All|*.*"
}; };
if (fileDialog.ShowDialog() != DialogResult.OK)
IWin32Window parent = App.Current.MainWindow.WpfWindow2WinFormWin32Window();
if (fileDialog.ShowDialog(parent) != DialogResult.OK)
{ {
return; return;
} }

View File

@@ -179,7 +179,13 @@ namespace ClashN.ViewModels
return; return;
} }
} }
if ((new PorfileEditWindow(item)).ShowDialog() == true)
PorfileEditWindow dialog = new PorfileEditWindow(item)
{
Owner = App.Current.MainWindow,
};
if (dialog.ShowDialog() == true)
{ {
RefreshProfiles(); RefreshProfiles();
} }

View File

@@ -125,7 +125,12 @@ namespace ClashN.ViewModels
}, this.IsValid()); }, this.IsValid());
SetGlobalHotkeyCmd = ReactiveCommand.Create(() => SetGlobalHotkeyCmd = ReactiveCommand.Create(() =>
{ {
new GlobalHotkeySettingWindow().ShowDialog(); GlobalHotkeySettingWindow dialog = new GlobalHotkeySettingWindow()
{
Owner = App.Current.MainWindow
};
dialog.ShowDialog();
}, this.IsValid()); }, this.IsValid());
//System proxy //System proxy