microsoft / microsoft/microsoft-ui-xaml

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

Open
#10,995 4 comments 2 reactions 0 assignees View on GitHub
area-ToolTip area-Windowing
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### 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

```csharp



```

```csharp
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 );
}
}

Contributor guide

Open the contributing guide

Research direction

Start with the minimal repro and compare AppWindow.Show() with Window.Activate() when OverlappedPresenter.IsModal is true. Reproduce the ToolTip hover failure after setting the owner window, then verify that the dialog is modal and ToolTip appears immediately after the issue is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.