2

我已经创建了 WPF 应用程序。在这个应用程序中

  1. 我正在启动win form exe。
  2. 稍后将 WPF 窗口作为此 win 表单的父级。
  3. 当我以当前分辨率执行此应用程序时。一切正常

但是当我通过 4K Monitor(3840 * 2100) 启动相同的东西时,表单大小会减小。

我尝试了以下事情。

  1. 将 win 窗体大小设置为窗口。最大化。
  2. 创建 WPF 清单并取消注释 DPIaware 以使 WPF 应用程序 DPIaware。
  3. 操纵父窗口的大小。

任何帮助或建议都会有所帮助。(仅供参考:当我尝试从 WinForms 启动相同的 exe 时,我没有看到这个问题)。

代码片段

/* mainwindow.xaml.cs*/
    var procInfo = new System.Diagnostics.ProcessStartInfo(ExeName, arguments);
    // Start the process
    var ProcessObj = System.Diagnostics.Process.Start(procInfo);
    var helper = new WindowInteropHelper(Window.GetWindow(this.grid1));
    SetParent(ProcessHandler, helper.Handle);

/* App.manifest */
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </windowsSettings>
  </application>
 
/*assemblyinfo.cs*/
[assembly: System.Windows.Media.DisableDpiAwareness]
4

1 回答 1

3

使用以下任何解决方案使 WPF dpi 不知道:

    /* App.manifest *
       <application xmlns="urn:schemas-microsoft-com:asm.v3">
       <windowsSettings>
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiAware>
    </windowsSettings>
  </application>
 

或者

    /*assemblyinfo.cs*/
     [assembly: System.Windows.Media.DisableDpiAwareness]
于 2020-11-17T09:51:18.073 回答