WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

Webview2 Windows Close Button Mouse Hover Highlight is still enabled while mouse is over WebView Control

Open thriller140 opened this issue 2 years ago • 3 comments

Description While using a <Window.Template> Windows Close Button is still highlighted after the user moves their mouse from the close button to the WebView. (Template Code will be provided below)

Version SDK: WebView2 1.0.1518.46 Runtime: WebView2.FixedVersionRuntime.109.0.1518.52.x64 Framework: WPF .NET 6.0 OS: Win10

Repro Steps

  1. Create a basic C# WPF .NET 6 Webview2 application
  2. In the MainWindow enable the Webview2 control and have it navigate to any web page (Code Below)
  3. Run the application
  4. After navigating to your web page, hover your mouse over the Close Button to see it highlight
  5. From there, move your mouse downward towards the Webview2 Control

Expected: Close Button will stop highlighting once your mouse leaves the button bounds

Actual: Close Button will continue to be highlighted until their mouse reaches the title bar

Additional context Setting a higher Height to the title bar so there is some title bar between the Close Button and the WebView2 control does not work if the user is moving their mouse downward fast.

MainWindow Code

MainWindow.xaml

<Window x:Class="Webview_App.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:local="clr-namespace:Webview_App" xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="-1" ResizeBorderThickness="0" CaptionHeight="30" NonClientFrameEdges="None" UseAeroCaptionButtons="True" />
    </WindowChrome.WindowChrome>
    <Window.Template>
        <ControlTemplate>
            <Grid Name="CustomTitleBar">
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>

                <Border Grid.Row="0" Opacity="1.0">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30" />
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,30,0">
                            <!-- Window Title - Center Aligned -->
                            <TextBlock
                                TextAlignment="Center" 
                                VerticalAlignment="Center"
                                Text="{Binding Title, RelativeSource={RelativeSource TemplatedParent}}" FontFamily="Segoe UI Semibold" />
                        </StackPanel>

                    </Grid>
                </Border>
                
                <Border Grid.Row="1" Background="White" Opacity="1.0" Margin="0,0,0,0">
                    <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/>
                </Border>
            </Grid>
        </ControlTemplate>
    </Window.Template>
    <Grid>
        <wv2:WebView2 Name="CustomWebView" />
    </Grid>
</Window>

MainWindow.cs

using System;
using System.Diagnostics;
using System.Windows;

namespace Webview_App
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            Dispatcher.BeginInvoke(new Action(() => InitializeWebView2Async()));
        }

        private async void InitializeWebView2Async()
        {
            try
            {
                await this.CustomWebView.EnsureCoreWebView2Async();
                this.CustomWebView.CoreWebView2.Navigate("https://microsoft.com/");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("failed to initialize webview");
            }
        }
    }
}

AB#43482343

thriller140 avatar Jan 24 '23 18:01 thriller140

Thanks for the bug report @thriller140 and sorry you're hitting this. I've opened a bug on our backlog to take a look.

champnic avatar Jan 31 '23 20:01 champnic

@thriller140 Is this a regression? Did this used to work?

champnic avatar Feb 23 '23 19:02 champnic

Hi @champnic the bug wasn't noticed until the time of posting this issue.

thriller140 avatar Feb 23 '23 22:02 thriller140