-
Notifications
You must be signed in to change notification settings - Fork 799
Open
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
- Create a secondary
Window - Configure its
AppWindowwithOverlappedPresenter.CreateForDialog()andIsModal = true - Set the owner window
- Show the window using
AppWindow.Show() - 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 );
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Type
Projects
Status
Backlog