Skip to content

ApplicationView.VisibleBoundsChanged is raised before Window.Bounds is updated #26666

Open

Description

@ajpinedam

Current behavior 🐛

ApplicationView.VisibleBoundsChanged is raised before the window size is updated. In its handler, Window.Bounds and XamlRoot.Size still have the old size, while ApplicationView.VisibleBounds already has the new value.

Logged on the iPhone 18 Pro simulator (iOS 27.0), rotating portrait → landscape → portrait:

VisibleBoundsChanged: Window.Bounds=0,0,402,874 XamlRoot.Size=402,874 VisibleBounds=62,0,750,382
XamlRoot.Changed: Window.Bounds=0,0,874,402 XamlRoot.Size=874,402 VisibleBounds=62,0,750,382
XamlRoot.Changed: Window.Bounds=0,0,874,402 XamlRoot.Size=874,402 VisibleBounds=62,0,750,382
VisibleBoundsChanged: Window.Bounds=0,0,874,402 XamlRoot.Size=874,402 VisibleBounds=0,62,402,778
XamlRoot.Changed: Window.Bounds=0,0,402,874 XamlRoot.Size=402,874 VisibleBounds=0,62,402,778
XamlRoot.Changed: Window.Bounds=0,0,402,874 XamlRoot.Size=402,874 VisibleBounds=0,62,402,778

The macOS desktop head shows the same order when the window is resized from 1024 × 640 to 900 × 500:

VisibleBoundsChanged: Window.Bounds=0,0,1024,640 XamlRoot.Size=1024,640 VisibleBounds=0,0,900,500
XamlRoot.Changed: Window.Bounds=0,0,900,500 XamlRoot.Size=900,500 VisibleBounds=0,0,900,500
XamlRoot.Changed: Window.Bounds=0,0,900,500 XamlRoot.Size=900,500 VisibleBounds=0,0,900,500

Code that compares the two in a VisibleBoundsChanged handler, for example to compute safe-area insets as Window.Bounds minus VisibleBounds, gets wrong values. On the iPhone Duo (iOS 27.1), rotating from landscape to portrait gives a right inset of 296 (the landscape width 678 minus the portrait visible width 382) instead of 84. Uno.Toolkit's SafeArea.WindowInsets computes insets this way, so it returns 296 when read in that handler.

Cause: NativeWindowWrapperBase.SetBoundsAndVisibleBounds raises VisibleBoundsChanged before it assigns _bounds and raises SizeChanged. Its doc comment says the events are "fired only after both properties are updated". BaseWindowImplementation forwards the first event to ApplicationView.VisibleBoundsChanged (through VisualTree.VisibleBounds), and the second to the window size update, Window.SizeChanged and XamlRoot.Changed.

Expected behavior 🎯

When ApplicationView.VisibleBoundsChanged is raised, Window.Bounds and XamlRoot.Size already have the new size, as the doc comment on SetBoundsAndVisibleBounds says.

How to reproduce it (as minimally and precisely as possible) 🔬

  1. dotnet new unoapp -preset blank

  2. Replace MainPage.xaml.cs with:

    using Windows.UI.ViewManagement;
    
    namespace BoundsOrder;
    
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            Loaded += (_, _) =>
            {
                var view = ApplicationView.GetForCurrentView();
                view.VisibleBoundsChanged += (s, _) =>
                    Console.WriteLine($"VisibleBoundsChanged: Window.Bounds={Window.Current!.Bounds} XamlRoot.Size={XamlRoot!.Size} VisibleBounds={s.VisibleBounds}");
                XamlRoot!.Changed += (s, _) =>
                    Console.WriteLine($"XamlRoot.Changed: Window.Bounds={Window.Current!.Bounds} XamlRoot.Size={s.Size} VisibleBounds={view.VisibleBounds}");
            };
        }
    }
  3. Run the iOS head on a simulator and rotate it, or run the desktop head on macOS and resize the window.

  • Expected: in the VisibleBoundsChanged lines, Window.Bounds and XamlRoot.Size have the new size.
  • Actual: they have the old size until XamlRoot.Changed.

Workaround 🛠️

Also handle XamlRoot.Changed (or Window.SizeChanged), which is raised after the size update, and recompute there. The Toolkit how-to for the iOS vertical bar does this (unoplatform/uno.toolkit.ui#1704).

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

iOS, Desktop (macOS)

Uno.Sdk version (and other relevant versions) 📦

Uno.Sdk 7.1.0-dev.25. SetBoundsAndVisibleBounds is unchanged on master at 1f89de4.

IDE version 🧑‍💻

N/A (.NET SDK 10.0.402 CLI, Xcode 27.1)

Anything else we need to know? 💬

  • Every runtime updates the window through SetBoundsAndVisibleBounds, so the other platforms likely have the same order. Android passes different bounds and visible bounds, like iOS. Only iOS and macOS desktop were run.
  • Assigning both fields before raising either event fixes Window.Bounds. XamlRoot.Size is updated by the SizeChanged handler, so it would also need SizeChanged to be raised before VisibleBoundsChanged.

Activity

  1. added
    kind/bug
    platform/macos 🍏
    platform/ios 🍎
    triage/untriaged
    on Nov 23, 2026
  2. self-assigned this
    on Nov 23, 2026
  3. added theissue type on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugplatform/ios 🍎platform/macos 🍏triage/untriaged

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions