6 jun

Fullscreen CefSharp element preloaded in the background is cropped on scaled displays

I need to preload a webpage in a CefSharp WPF browser element in the background (before a containing Window is visible). After inspecting the CefSharp sources, I found that rendering of web starts only if the size property of the CefSharp element is not empty (see: https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Wpf/ChromiumWebBrowser.cs#L1511).

So I made some changes in my code - instead of declaring the CefSharp element in XAML, I moved it to the constructor of my fullscreen window (which is called on app start):

public partial class FullscreenWindow : Window
    public FullscreenWindow()

    private void PreloadBrowser()
        var browser = new ChromiumWebBrowser();
        browser.SetBinding(ChromiumWebBrowser.AddressProperty, new Binding("Address") { Source = ViewModel, Mode = BindingMode.TwoWay });
        browser.SetBinding(ChromiumWebBrowser.WebBrowserProperty, new Binding("WebBrowser") { Source = ViewModel, Mode = BindingMode.OneWayToSource });
        browser.Arrange(new Rect(0,0,1,1)); // Workaround to start rendering of web before Window is visible
        Content = browser;

On most systems everything works fine - browser.Arrange sets the size to the CefSharp element, so it renders the web instantly after Address is changed and web is displayed already rendered after calling the Window.Show().

But, if a user has system display scale set to other than 100% (Display settings -> Change the size of text, apps, and other items) - for example to 125%, browser is rendered cropped. When a line browser.Arrange(new Rect(0,0,1,1)); is commented out CefSharp is displayed correctly, but of course is not preloaded in the background.

How to avoid this? Or is there any better way to preload the web in the background?



© 2017 website by Rubit Corporation