Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(sometimes) control not fully fill window at first loaded #432

Closed
cuiliang opened this issue Sep 12, 2020 · 21 comments
Closed

(sometimes) control not fully fill window at first loaded #432

cuiliang opened this issue Sep 12, 2020 · 21 comments
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@cuiliang
Copy link

cuiliang commented Sep 12, 2020

Description
When window first show, some time it will show on only part of window.
After mouse move over webview or move/resize window, it will be stretched to full window.
code:

<DockPanel>
        <wv2:WebView2 Name="webView"
                          Source="https://www.microsoft.com"
            />
        </DockPanel>

image

Version
SDK: 0.9.628-prerelease
Runtime: 87.0.637.0
Framework: WPF with .Net 4.6.2
OS: Windows 10 2004(19041.450) , Windows 10 1909
Display: 3840*2160, display ratio: 150%

Repro Steps

Screenshots
image

It also happend with my own application.
problem

Additional context
This not always happen, only some times.
It seems like something related to dpi scale.

AB#28658107

@cuiliang cuiliang added the bug Something isn't working label Sep 12, 2020
@cuiliang
Copy link
Author

Here is a sample project.
Execute "\bin\x64\Debug\WpfApp2.exe" window will like this:
image

When debuging in visual studio, it works normally.

WpfApp2.zip

@champnic
Copy link
Member

Thanks for filing this @cuiliang! This is a known issue (but didn't have a GitHub issue yet), and we'll take a look next sprint.

@champnic champnic added the tracked We are tracking this work internally. label Sep 12, 2020
@cuiliang
Copy link
Author

Any workground on this issue?
Adding 'window.UpdateLayout()' to Loaded event handler has no effect.

@champnic
Copy link
Member

No, we haven't started taking a look at this yet. I'll update you when we have more info. Thanks!

@cgeier
Copy link

cgeier commented Sep 21, 2020

@cuiliang The issue didn't occur when I tried your project. Have you tried setting HorizontalAlignment="Stretch" and VerticalAlignment="Stretch" ?

<wv2:WebView2 Name = "webView"
              Source = "https://www.microsoft.com"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch" />

There does seem to be a little bit of a delay when starting one's program when the web cache files/folders don't exist yet. Not sure if it would make a difference or not, but you could try programmatically initializing "CoreWebView2" by calling EnsureCoreWebView2Async.

Subscribe to the Window "Loaded" event by adding Loaded="Window_Loaded"

MainWindow.xaml

<Window x:Class="WebView2Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
        xmlns:local="clr-namespace:WebView2Test"
        mc:Ignorable="d"
        Loaded="Window_Loaded"
        Title="MainWindow" Height="450" Width="800">

Don't set Source property, as this causes initialization to occur.

<wv2:WebView2 Name = "webView21"
              CoreWebView2Ready="webView21_CoreWebView2Ready"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch" />

Then in MainWindow.xaml.cs, add the following code:

MainWindow.xaml.cs

public MainWindow()
{
    InitializeComponent();
}

private async void Window_Loaded(object sender, RoutedEventArgs e)
{
    //initialize CoreWebView2
    await webView21.EnsureCoreWebView2Async();

    //set Source property - navigate to URL
    webView21.Source = new Uri("https://www.microsoft.com", UriKind.Absolute);
}

private void webView21_CoreWebView2Ready(object sender, EventArgs e)
{
    //ToDo: subscribe to desired events (add event handlers) - CoreWebView2

}

@cuiliang
Copy link
Author

@cgeier
It only happens on high dpi screen.

Run program directly from output folder, not from visual studio.
I use await webView21.EnsureCoreWebView2Async(); in another program, It also have this problem.

I have also tried call 'UpdateLayout()' from window Loaded event handler, but have no effect.

@champnic
Copy link
Member

We've got a fix for this, and it should be available next release (around mid October). In the meantime, you should be able to workaround the issue by calling webView.UpdateWindowPos() after EnsureCoreWebViewAsync is completed (or in CoreWebView2Ready event handler). This will cause a WindowPosChanging event in our control which will correctly update the window bounds.

@cuiliang
Copy link
Author

@champnic webView.UpdateWindowPos() works, thank you!

@champnic
Copy link
Member

This should now be fixed in WebView2 SDK 1.0.674-prerelease. If this is still an issue please let us know. Thanks!

@champnic champnic added this to the SDK 1.0.674-prerelease milestone Oct 19, 2020
@ukandrewc
Copy link

Looks like this one is back in V1.0.707.0

@champnic
Copy link
Member

champnic commented Dec 3, 2020

Thanks for the heads up. We'll take another look...

@champnic champnic reopened this Dec 3, 2020
@champnic
Copy link
Member

champnic commented Dec 7, 2020

@ukandrewc We've been unable to repro this bug. Do you have a repro sample you could share, or other machine setup info?

@ukandrewc
Copy link

ukandrewc commented Dec 7, 2020

@champnic Sorry, I'm not seeing it all the time, it's while resizing during initialisation. Will try and get a repro together, in the mean time, a screenshot (WebView2.Dock = DockStyle.Fill, resized manually when form opened) Win32, Winforms Latest Dev Edge :

image

@champnic
Copy link
Member

champnic commented Dec 8, 2020

Ah, I don't think we've been trying to test other explicit resizing during initialization - the original bug was with just a default "Create a webview" behavior we would see the broken resizing. My guess is the control takes the current expected bounds when it begins initialization and uses those, and then misses the updated size until it's done initializing, at which point it starts listening for changes. The fix may be something like having the control re-check bounds when it hooks up to size listening.

Let me know if you do get a repro sample/app, as that will make verifying this much easier. Thanks!

@ukandrewc
Copy link

@champnic Will do, just a bit up against with my day job at the moment ;-)

@ukandrewc
Copy link

@champnic I think this is me, possibly due to a WebView2 change, I'm not sure.

I was enabling DevTools Protocol events in CoreWebView2InitializationCompleted:

CoreWebView2.CallDevToolsProtocolMethodAsync("Page.enable", "{}")

This is deadlocking. I don't think it was prior to 1.0.707.0, but not sure. Has the CoreWebView2 event changed from Async to Sync? because I'm sure this used to work.

Anyway, I've moved "Page.enable" now, and I can't reproduce the issue any more.

@champnic
Copy link
Member

@ukandrewc The events are still async in general, though there are parts of it that are sync (setup for the CDP call). Where did you move the call to that's working? If you move it back, do you hit the same deadlock issue (it's reproducible)?

@ukandrewc
Copy link

@champnic This is me, because I'm waiting for the result of the call. It is a little odd, because using PushFrame prevents the task completing. I don't know you need to know, but this is what I've found:

Sub CoreWebView2InitializationCompleted(sender As Object, e As CoreWebView2InitializationCompletedEventArgs)

  'Task doesn't complete
  Dim Task = CoreWeb.CallDevToolsProtocolMethodAsync("Page.enabled", "{}")
  Task.ContinueWith(Sub() Frame.Continue = False)

  Frame.Continue = True
  Dispatcher.PushFrame(Frame)

End Sub
Sub CoreWebView2InitializationCompleted(sender As Object, e As CoreWebView2InitializationCompletedEventArgs)

  'Task completes but is faulted
  Dim Task = CoreWeb.CallDevToolsProtocolMethodAsync("Page.enabled", "{}")
  Task.ContinueWith(Sub() 'Task.IsFaulted True here)

End Sub

@johna-ms
Copy link
Contributor

@ukandrewc any luck on a repro? I haven't been able to repro anything.

@ukandrewc
Copy link

ukandrewc commented Jan 28, 2021

@johna-ms In my case, it was my fault.

@champnic
Copy link
Member

Thanks for the follow-up - closing this for now. Let us know if you see this again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

5 participants