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

Problem when changing WebView2 control’s parent visibility #1094

Open
Lukasz736 opened this issue Mar 19, 2021 · 7 comments
Open

Problem when changing WebView2 control’s parent visibility #1094

Lukasz736 opened this issue Mar 19, 2021 · 7 comments
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.

Comments

@Lukasz736
Copy link

Lukasz736 commented Mar 19, 2021

Our development:
SDK: 1.0.705.50/1.0.774.44
Runtime: Canary 91.0.830.0 x64
Framework: .NET Core 3.1, WPF, x64
OS: Windows 10 Pro x64

We have simple problem when we change visibility of WebView2 control's parent with WebView2 and Edge Canary. In WPF we put Canvas on Grid and on Grid we have WebView2 control. Canvas has Visibility = Hidden, like below:

<Grid Background="Aqua">
    <Canvas Name="Can" Width="500" Height="500" Visibility="Hidden">
        <wpf:WebView2 Name="Web" Width="500" Height="500" />
    </Canvas>
</Grid>

After that we load sample HTML document, when application starts, Canvas is hidden:

public MainWindow()
{
    InitializeComponent();
    Web.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "sample.html");
} 

After few seconds, we change Canvas Visibility to true:

Application.Current.Dispatcher.Invoke(() =>
{
    Can.Visibility = Visibility.Visible;
});

Our result:
https://pagspzoo-my.sharepoint.com/:i:/g/personal/lukasz_kozek_pag_com_pl/EabQlEZxS_lFjNZVeXvdIDkBtlQ4MglClzCnfSDpnNRGYQ

We don’t see HTML document, only gray field. When we minimize and maximize main window, HTML shows. Grey field we can see in 1.0.705.50 of WebView2 version.
When we upgarde this control to 1.0.774.44 version, we don’t see grey field, only Grid with Aqua color. We have the same situation like above, after minimize and maximize main window, HTML shows.

Below I share source of sample application. First, with older version WebView2 and grey field, and newest version.

Source with 1.0.705.50 (gray field)
https://pagspzoo-my.sharepoint.com/:u:/g/personal/lukasz_kozek_pag_com_pl/EQMNEObCCsZMmUzm7QztIQcBTxxgkLMRiEgDRuVDVWprkg?e=h8lHBf

Source with 1.0.774.44
https://pagspzoo-my.sharepoint.com/:u:/g/personal/lukasz_kozek_pag_com_pl/ESsadCGN0zJOpTB03KaJ0iYBCJ4LvjjbNwBDNUQ1zwpTqQ?e=GTx0Ns

Thank You for any advice.

AB#32255210

@Lukasz736 Lukasz736 added the bug Something isn't working label Mar 19, 2021
@champnic
Copy link
Member

Hey @Lukasz736 - you may need to call WebView2.Show() if the Canvas isn't automatically calling Show/Hide on it's children. Can you give that a try?

@Lukasz736
Copy link
Author

We don't see available method Show() in WebView2 control. We tried to manipulate with Visibility property, but without possitive result.

@champnic champnic added the tracked We are tracking this work internally. label Mar 25, 2021
@champnic
Copy link
Member

I was able to repro using your app and have added this bug to our backlog to debug further. If you drag the window, does it show up properly?

I wasn't able to repro if I changed the visibility using a button instead of a timer, so I wonder if the user interaction helps there. Depending on why you are hiding and then showing it, you can try listening to the WebView2 loading events (for example, WebView2.NavigationCompleted) to show it when ready instead of a timer, but I'm not sure if that runs into the same issue.

@champnic
Copy link
Member

I was able to workaround this issue easily by adding Web.UpdateWindowPos() call after showing the canvas. Can you try that for now?

@Lukasz736
Copy link
Author

I was able to workaround this issue easily by adding Web.UpdateWindowPos() call after showing the canvas. Can you try that for now?

This workaround solve our problem with visibility of HTML document.

@kitgrose
Copy link

kitgrose commented Oct 8, 2021

I think I'm having a related issue to this. I'm running WinUI 2.8.0-prerelease.210927001 under UWP.

If the parent container goes from collapsed to visible, the view is rendered, but is not interactive (scrolling, clicking, etc. is all ignored). The web view is able to be resized and it correctly updates the layout, etc.

I don't see any UpdateWindowPos() method on the web view control though.

@champnic
Copy link
Member

champnic commented Oct 8, 2021

Hey @kitgrose - for WinUI 2 issues, you can start with the WinUI repo:
https://github.com/microsoft/microsoft-ui-xaml/issues

@github-actions github-actions bot added the priority-low We have considered this issue and decided that we will not be able to address it in the near future. label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants