WebView icon indicating copy to clipboard operation
WebView copied to clipboard

Incorrect Page Layout and Context Menu Position with Avalonia 11.2.3 and WebView 3.120.8

Open Jackhammer88 opened this issue 10 months ago • 1 comments

Description:

When using Avalonia 11.2.3 with WebView 3.120.8, there are two layout-related issues:

Incorrect page layout on startup: The initial page rendering does not match the window size, resulting in a layout issue. Context menu misplacement: When right-clicking inside the WebView without manually resizing the window first, the context menu often appears at incorrect coordinates.

Steps to Reproduce:

  1. Create a basic Avalonia app with WebView (e.g., Avalonia 11.2.3 and WebView 3.120.8).
  2. Set WebView to fill the window.
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:AvaloniaApplication2.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:webview="clr-namespace:WebViewControl;assembly=WebViewControl.Avalonia"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaApplication2.Views.MainWindow"
        x:DataType="vm:MainWindowViewModel"
        Icon="/Assets/avalonia-logo.ico"
        Title="AvaloniaApplication2">

    <Design.DataContext>
        <vm:MainWindowViewModel/>
    </Design.DataContext>

    <webview:WebView x:Name="webview" Focusable="True" Address="{Binding Address}" />

</Window>
  1. Set code of view model like this:
public partial class MainWindowViewModel : ViewModelBase
{
    public string Address { get; set; } = "http://your.web/site";
}
  1. Run the application (without resizing the window).
  2. Observe the page layout.
  3. Right-click inside the WebView to open the context menu.

Expected Behavior:

The page should be rendered correctly to fit the window on startup. The context menu should appear at the correct position under the cursor.

Actual Behavior:

The page layout is incorrectly sized on startup. The context menu appears at the wrong coordinates if the window size has not been manually adjusted.

Environment:

Avalonia: 11.2.3 WebView: 3.120.8 OS: ALT Linux Starterkit 11 (Salvia) .NET: 8

Additional Context:

It seems the WebView component is not recalculating its layout properly on the initial window creation. Manually resizing the window corrects both the page layout and context menu placement.

Jackhammer88 avatar Feb 18 '25 08:02 Jackhammer88