1

我正在尝试将 IE Web 浏览器窗口转换为 CefSharp (v 96.0.180) 窗口作为更大 WPF 应用程序的一部分。应用程序本身遵循系统 dpi 级别(使用它调整 UI 大小),但无论系统设置如何,IE 窗口都保持 100% dpi。​当我将控件转换为 CefSharp 时,它会开始跟随系统 dpi。问题是页面在任何超过 100% 的 dpi 上都被放大且丑陋。

为了检查 Cefsharp 窗口行为,我尝试使用应用程序清单将 dpi 感知设置为 true 或 per monitor,但它不起作用(而且我担心它会为整个应用程序设置它,而我只需要它对于一个窗口/项目)。

有没有办法实现它?

编辑:每个请求的代码:BrowserView.xaml:

<Grid>
<ContentControl Name="wBrowser" RenderOptions.BitMapScalingMode="HighQuality" />
</Grid>

BrowserView.xaml.cs:

public BrowserView()
{
    CefRuntime.SubscribeAnyCpuAssemblyResolver();
    Cef.EnableHighDPISupport();
    LoadApp();
    InitializeComponent();
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void LoadApp()
{
    var settings = new CefSettings()
    {
        CachePath = _cachePath,
        LogSeverity = LogSeverity.Disable
    };
    //settings.CefCommandLineArgs.Add("high-dpi-support", "1");
    //settings.CefCommandLineArgs.Add("force-device-scale-factor", "1");
    settings.CefCommandLineArgs.Add("disable-gpu-compositing");
    Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
}

(我还尝试将这些调用移动到我在 CefSharp wiki/GeneralUsage 中创建的 App.xaml.cs Main 方法。这些是 Main 中的第一个调用。没有效果,无论我作为命令行参数放什么。)

在加载控件时触发的事件的事件处理程序中的同一 BrowserView.xaml.cs 文件中:

var chromiumWebBrowser = new ChromiumWebBrowser();
wBrowser.Content = chromiumWebBrowser;
// call to Window.Show() here
chromiumWebBrowser.LoadUrl(url);

总之,如果我将系统设置切换为 DPI 100% 并重新运行应用程序,上述任何操作都不会使窗口看起来像它的样子(而这种外观正是我所需要的)。

4

0 回答 0