Skip to content

[Skia] ToolTip shows an empty border on first open when its content realizes after load (e.g. ItemsControl) #24820

Closed

Description

@Xiaoy312

Current behavior 🐛

On Skia, a ToolTip whose content only fills itself in once it is in the visual tree shows an empty border the first time it opens. An ItemsControl is the common case: it only creates its item containers after it loads. The content stays empty for as long as that first open lasts. Closing and reopening the tooltip shows the content correctly, because by then the containers already exist when the tooltip is measured.

A ToolTip with plain string or other static content is not affected.

Root cause: ToolTip.AttachToPopup sets the tooltip's parent back to its previous value right after Popup.Child = this (to keep the owner's DataContext flowing in). UIElement.InvalidateParentMeasureDirtyPath walks that parent, so a measure invalidation raised inside the open tooltip marks the ToolTip and stops there. The PopupPanel is never marked, and no layout pass re-measures the tooltip. Dirty flags right after invalidating from inside an open tooltip:

content   measureDirty=True   measureDirtyPath=True
ToolTip   measureDirty=False  measureDirtyPath=True     <- path stops here
panel     measureDirty=False  measureDirtyPath=False    <- never marked

Calling InvalidateMeasure() on the content or the tooltip, or UpdateLayout(), doesn't help. Only PopupPanel.InvalidateMeasure() or re-setting Popup.Child makes the content appear.

Expected behavior 🎯

The tooltip is re-measured once its content has realized, and shows the items on its first open, as it does on WinUI and on every later open.

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

  1. dotnet new unoapp (Skia renderer), add a Button x:Name="MyButton" to MainPage.
  2. In code-behind:
public MainPage()
{
    this.InitializeComponent();

    var items = new ItemsControl { ItemsSource = new[] { "first error", "second error" } };
    ToolTipService.SetToolTip(MyButton, new ToolTip { Content = items });
}
  1. Run on Desktop, hover the button.
  2. Observe: the tooltip shows only its border and padding. Move away and hover again: the two items now show.

Runtime test that reproduces it (fails on master):

[TestMethod]
public async Task When_Content_Realizes_On_Load_Then_Measured_On_First_Open()
{
    var items = new ItemsControl { ItemsSource = new[] { "first error", "second error" } };
    var SUT = new ToolTip { Content = items };

    var owner = new Button { Content = "target" };
    ToolTipService.SetToolTip(owner, SUT);

    try
    {
        TestServices.WindowHelper.WindowContent = owner;
        await TestServices.WindowHelper.WaitForLoaded(owner);

        SUT.IsOpen = true;

        await TestServices.WindowHelper.WaitFor(
            () => items.ActualWidth > 0 && items.ActualHeight > 0,
            timeoutMS: 3000,
            message: "the tooltip's content was never measured on its first open");
    }
    finally
    {
        SUT.IsOpen = false;
        VisualTreeHelper.CloseAllPopups(TestServices.WindowHelper.XamlRoot);
    }
}

Workaround 🛠️

After the tooltip opens and its content has loaded, call InvalidateMeasure() on the tooltip's Popup panel (internal), or set the popup's Child to null and back. Neither is reachable from app code, so there's no clean public workaround.

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

All platforms 🌍

Uno.Sdk version (and other relevant versions) 📦

master, and Uno.WinUI 7.0.0-dev.701 (net10.0-desktop).

IDE version 🧑‍💻

Not IDE related (dotnet CLI).

Anything else we need to know? 💬

We hit this with an error-message tooltip whose content is an ItemsControl bound to a list of messages. Same root cause as #24557 (an Image whose bitmap arrives after the tooltip opened); see comments below.

Activity

  1. added
    triage/untriaged
    on Sep 29, 2026
  2. Xiaoy312 commented on Sep 29, 2026

    @Xiaoy312
    ContributorAuthor

    Related to #24557: same root cause, different trigger. There, an Image inside an open tooltip gets its bitmap after the tooltip opened; here, an ItemsControl creates its containers after the first measure. In both, the measure invalidation stops at the ToolTip because AttachToPopup restores the tooltip's previous parent.

    @mikernet's PR #24592 (keep the PopupPanel as parent while the tooltip is open) fixes this issue too. Checked on Skia desktop by applying the test above to the PR branch (eb38bcbb84):

    ToolTip.cs When_Content_Realizes_On_Load_Then_Measured_On_First_Open (this issue) When_Image_Source_Loads_While_Open (#24557)
    PR #24592 ✅ Passed ✅ Passed
    PR fix reverted ❌ Failed ❌ Failed

    It would be worth adding this test to #24592 so it covers the ItemsControl case as well.

  3. Xiaoy312 commented on Sep 29, 2026

    @Xiaoy312
    ContributorAuthor

    For reference, here is the fix we wrote for this issue before finding #24592.

    It only fixes the ItemsControl case in this issue, not the Image case in #24557. It forwards the tooltip's measure-dirty state to the PopupPanel from LayoutUpdated, while the tooltip is open. That works here because the ItemsControl invalidates while the first-open layout pass is still running, so LayoutUpdated is raised afterwards. A bitmap that arrives after layout has settled doesn't start a new pass, because the dirty path dead-ends at the ToolTip. So LayoutUpdated never fires and the handler never runs. Measured on Skia desktop:

    ToolTip.cs ItemsControl test (this issue) Image test (#24557)
    This fix ✅ Passed ❌ Failed
    PR #24592 ✅ Passed ✅ Passed

    #24592 repairs the parent chain itself, so it's the better fix. This is posted only as an alternative that leaves parenting and DataContext untouched. It covers measure only; an arrange invalidation inside an open tooltip is still lost.

    ToolTip.cs
    diff --git a/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs b/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs
    index 7bc5e59bad..c641ea009d 100644
    --- a/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs
    +++ b/src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTip.cs
    @@ -146,6 +146,7 @@ namespace Microsoft.UI.Xaml.Controls
     				ForwardOwnerThemePropertyToToolTip();
     				AttachToPopup();
     				SubscribeOwnerThemeChanged();
    +				SubscribeRelayoutThroughPopupPanel();
     
     				Opened?.Invoke(this, new RoutedEventArgs(this));
     				GoToElementState("Opened", useTransitions: true);
    @@ -160,11 +161,58 @@ namespace Microsoft.UI.Xaml.Controls
     			else
     			{
     				UnsubscribeOwnerThemeChanged();
    +				UnsubscribeRelayoutThroughPopupPanel();
     				Closed?.Invoke(this, new RoutedEventArgs(this));
     				GoToElementState("Closed", useTransitions: true);
     			}
     		}
     
    +		/// <summary>
    +		/// Uno only. While the tooltip is open, forwards a measure invalidation raised inside it to the
    +		/// popup's panel, which is the nearest element above the tooltip that a layout pass still reaches.
    +		/// </summary>
    +		/// <remarks>
    +		/// <see cref="AttachToPopup"/> hands this tooltip to the popup and then puts its parent back, so
    +		/// that the owner's DataContext keeps flowing in rather than the PopupPanel's — see the comment
    +		/// there. What that costs is the layout dirty path: <c>InvalidateParentMeasureDirtyPath</c> walks
    +		/// the DependencyObject parent, which is the owner's now, and the owner never measures a tooltip.
    +		/// So an invalidation raised inside the tooltip marks the tooltip and stops, and the popup is never
    +		/// measured again for as long as it stays open.
    +		/// <para>
    +		/// It only shows with content that is not fully realized when the tooltip is first measured —
    +		/// content whose own children arrive on load, an ItemsControl materializing its containers being
    +		/// the usual one. That content is measured while it is still empty, keeps a zero desired size, and
    +		/// the tooltip shows its border and nothing inside it until it is closed and opened again. Static
    +		/// content is measured once and correctly, which is why this went unnoticed.
    +		/// </para>
    +		/// <para>
    +		/// Measure only. <c>InvalidateParentArrangeDirtyPath</c> dead-ends on the same restored parent, so
    +		/// an arrange raised inside an open tooltip is still lost; nothing has been seen to need it, and
    +		/// re-measuring is what the size of a popup follows from.
    +		/// </para>
    +		/// </remarks>
    +		private void SubscribeRelayoutThroughPopupPanel()
    +		{
    +			LayoutUpdated -= OnLayoutUpdatedRelayoutPopupPanel;
    +			LayoutUpdated += OnLayoutUpdatedRelayoutPopupPanel;
    +		}
    +
    +		/// <inheritdoc cref="SubscribeRelayoutThroughPopupPanel"/>
    +		private void UnsubscribeRelayoutThroughPopupPanel()
    +			=> LayoutUpdated -= OnLayoutUpdatedRelayoutPopupPanel;
    +
    +		/// <inheritdoc cref="SubscribeRelayoutThroughPopupPanel"/>
    +		private void OnLayoutUpdatedRelayoutPopupPanel(object? sender, object e)
    +		{
    +			// Dirtying the panel schedules the pass that descends back into the tooltip, where the dirty
    +			// path set by the invalidation is still waiting. The pass clears it, so this settles rather
    +			// than looping: a tooltip whose subtree is clean asks for nothing.
    +			if (IsOpen && IsMeasureDirtyOrMeasureDirtyPath && _popup?.PopupPanel is { } panel)
    +			{
    +				panel.InvalidateMeasure();
    +			}
    +		}
    +
     		private void AttachToPopup()
     		{
     			if (Parent == null)
    Given_ToolTip.cs (test)
    diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ToolTip.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ToolTip.cs
    index 9769160c83..4b5a2621cc 100644
    --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ToolTip.cs
    +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ToolTip.cs
    @@ -643,6 +643,44 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
     				tooltip.IsOpen = false;
     #if HAS_UNO
     				VisualTreeHelper.CloseAllPopups(TestServices.WindowHelper.XamlRoot);
    +#endif
    +			}
    +		}
    +
    +		[TestMethod]
    +		public async Task When_Content_Realizes_On_Load_Then_Measured_On_First_Open()
    +		{
    +			// An ItemsControl only materializes its containers once it is in the tree, which is after the
    +			// tooltip has first been measured. That first measure therefore sees an empty panel, and the
    +			// content needs a second pass before it has any size at all.
    +			//
    +			// In Uno that second pass is not free: AttachToPopup puts the tooltip's parent back after
    +			// handing it to the popup, so a measure dirty path raised inside the tooltip stops at the
    +			// tooltip and never reaches the PopupPanel. With nothing forwarding it, the first open showed
    +			// the tooltip's border around nothing and only the second open was right.
    +			var items = new ItemsControl { ItemsSource = new[] { "first error", "second error" } };
    +			var SUT = new ToolTip { Content = items };
    +
    +			var owner = new Button { Content = "target" };
    +			ToolTipService.SetToolTip(owner, SUT);
    +
    +			try
    +			{
    +				TestServices.WindowHelper.WindowContent = owner;
    +				await TestServices.WindowHelper.WaitForLoaded(owner);
    +
    +				SUT.IsOpen = true;
    +
    +				await TestServices.WindowHelper.WaitFor(
    +					() => items.ActualWidth > 0 && items.ActualHeight > 0,
    +					timeoutMS: 3000,
    +					message: "the tooltip's content was never measured on its first open");
    +			}
    +			finally
    +			{
    +				SUT.IsOpen = false;
    +#if HAS_UNO
    +				VisualTreeHelper.CloseAllPopups(TestServices.WindowHelper.XamlRoot);
     #endif
     			}
     		}
  4. added theissue type on Sep 29, 2026
  5. added a commit that references this issue on Sep 30, 2026
    f0d86ec
  6. added
    7.1
    on Oct 14, 2026
  7. removed
    7.1
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/untriaged

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions