WPF ShowDialog在开始的进程中没有阻止当前进程的主窗口

问题描述 投票:0回答:1

我有使用WPF窗口启动进程的窗口应用程序。我将当前进程ID发送到启动进程,因此WPF窗口可以正确设置所有者:

MainWindow mainWindow = new MainWindow();
int parentProcessId = int.Parse(e.Args[0]);
System.Diagnostics.Process parentProcess = System.Diagnostics.Process.GetProcessById(parentProcessId);
WindowInteropHelper helper = new WindowInteropHelper(mainWindow);
helper.Owner = parentProcess.MainWindowHandle;
mainWindow.ShowDialog();

Alt + Tab正常工作-WPF窗口阻止了父窗口。但这不会阻止父寡妇的控件,因此我可以按下父窗口中的每个按钮,甚至将其关闭。

我正在像这样开始新的过程:

string arguments = Process.GetCurrentProcess().Id.ToString();
ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "WPF.App.exe"), arguments);
Process.Start(startInfo);

我如何打开WPF窗口,以便它阻止所有者窗口的控件(并且不仅显示在顶部,而且阻止Alt + Tab)?

谢谢。

c# wpf process showdialog
1个回答
0
投票

假设父进程也是WPF应用程序:

private void SomeMethod()
{
    string arguments = Process.GetCurrentProcess().Id.ToString();
    ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "WPF.App.exe"), arguments);
    childProcess = Process.Start(startInfo);
    childProcess.Exited += childProcess_Exited;
    childProcessWaitFrame = new DispatcherFrame;
    Dispatcher.PushFrame(childProcessWaitFrame);
}

private void childProcess_Exited(object sender, EventArgs e)
{
    childProcessWaitFrame.Continue = false;
}
© www.soinside.com 2019 - 2024. All rights reserved.