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

Moving WebView2 to another window still routes window message to previous window #9175

Closed
HO-COOH opened this issue Dec 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@HO-COOH
Copy link

HO-COOH commented Dec 18, 2023

Describe the bug

There is a scenario where I need to stack two WebView2 controls on top of each other, and then when user clicks a button, one WebView2 pops up as a new window. Originally I asked the question here
I tried removing the WebView2 from a Grid in the old window and make it as a child to the Grid in the new window, and it seems to be working, except that when interacting with the new window, the old window gets activated and bought to the front of the new window.

My method might be wrong, but doing the same thing with other controls such as a ToggleButton gives expected behavior, and does not activate the previous window.

Steps to reproduce the bug

  1. In MainWindow.xaml
<Window
    ...
    <Grid x:Name="RootGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <WebView2 x:Name="Browser" Source="https://www.google.com"/>
        <Button Click="Button_Click" Grid.Row="1">Move</Button>
    </Grid>
  1. Create another window, call it BlankWindow
<Window
    ...
    <Grid x:Name="RootGrid" Background="Red"/>
  1. In the button handler code,
void winrt::WinUI3Cpp2::implementation::MainWindow::Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
    winrt::WinUI3Cpp2::BlankWindow window;
    
    window.Activated([this, window](auto...)
        {
            static bool called = false;
            if (called)
                return;

            window.RootGrid().Loaded(
                [this, window](auto...)
                {
                    auto webview = Browser();
                    RootGrid().Children().RemoveAt(0);
                    window.RootGrid().Children().Append(webview);
                }
            );
            called = true;
        });
    window.Activate();
}

Expected behavior

The previous window should not get activated.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.5 Experimental 1: 1.5.231202003-experimental1

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

@HO-COOH HO-COOH added the bug Something isn't working label Dec 18, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Dec 18, 2023
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@HO-COOH
Copy link
Author

HO-COOH commented Dec 18, 2023

Duplicate of #7335

@HO-COOH HO-COOH closed this as completed Dec 18, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added needs-triage Issue needs to be triaged by the area owners and removed needs-triage Issue needs to be triaged by the area owners labels Dec 18, 2023
@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Sep 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
Projects
None yet
Development

No branches or pull requests

2 participants