Skip to content

Modal Window shown via AppWindow.Show() does not activate XAML Window, causing ToolTip hover to fail #10995

@hamu777

Description

@hamu777

Describe the bug

Description

When showing a modal dialog using AppWindow.Show() with OverlappedPresenter.IsModal = true,
the underlying XAML Window does not appear to become activated.
As a result, hover-based input such as ToolTip does not work until the window is manually reactivated.

This happens even when the ToolTip content is hard-coded and no XAML data binding is used.

Calling Window.Activate() fixes the ToolTip issue, but breaks the modal behavior.

Steps to reproduce the bug

  1. Create a secondary Window
  2. Configure its AppWindow with OverlappedPresenter.CreateForDialog() and IsModal = true
  3. Set the owner window
  4. Show the window using AppWindow.Show()
  5. Hover over a control that has a ToolTip

Result

The ToolTip does not appear.

Expected Behavior

  • The modal dialog should activate the XAML window
  • ToolTip hover should work immediately when the dialog is shown

Actual Behavior

  • The window appears visually, but the XAML window is not activated
  • ToolTip hover does not work
  • ToolTip starts working only after the window is reactivated (e.g. clicking the title bar)
  • Calling Window.Activate() restores ToolTip behavior but breaks modality

Minimal Repro Code

<Window
  x:Class="ModalWindowExample.ModalWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="ModalWindow">

  <Grid>
    <TextBlock Text="Text to display"
               ToolTipService.ToolTip="Tooltip content"
               VerticalAlignment="Center"
               HorizontalAlignment="Center"
               FontSize="16"/>
  </Grid>
</Window>
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using System;
using System.Runtime.InteropServices;
using WinRT.Interop;

namespace ModalWindowExample
{
  public sealed partial class ModalWindow : Window
  {
    private readonly Window _parent;

    public ModalWindow( Window parent )
    {
      InitializeComponent();
      _parent = parent;

      this.SetWindowOwner( _parent );

      OverlappedPresenter presenter = OverlappedPresenter.CreateForDialog();
      presenter.IsResizable = true;
      presenter.IsMinimizable = false;
      presenter.IsMaximizable = false;
      presenter.IsModal = true;

      this.AppWindow.Resize( new( 300, 300 ) );
      this.AppWindow.SetPresenter( presenter );
      this.AppWindow.Show();
    }

    private void SetWindowOwner( Window owner )
    {
      IntPtr ownerHwnd = WindowNative.GetWindowHandle( owner );
      IntPtr ownedHwnd = Win32Interop.GetWindowFromWindowId( this.AppWindow.Id );
      if( IntPtr.Size == 8 )
        SetWindowLongPtr( ownedHwnd, -8, ownerHwnd );
      else
        SetWindowLong( ownedHwnd, -8, ownerHwnd );
    }

    [DllImport( "user32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr" )]
    public static extern IntPtr SetWindowLongPtr( IntPtr hWnd, Int32 nIndex, IntPtr dwNewLong );

    [DllImport( "user32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong" )]
    public static extern IntPtr SetWindowLong( IntPtr hWnd, Int32 nIndex, IntPtr dwNewLong );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions