Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToolTip throws when TextElement is removed from view #9264

Open
FrayxRulez opened this issue Jan 19, 2024 · 1 comment
Open

ToolTip throws when TextElement is removed from view #9264

FrayxRulez opened this issue Jan 19, 2024 · 1 comment
Labels
area-ToolTip bug Something isn't working team-Controls Issue for the Controls team

Comments

@FrayxRulez
Copy link

Describe the bug

ToolTip throws an unhandled NotSupportedException when opening (or closing) for a TextElement that's no longer owned by any (Rich)TextBlock.
This happens because to position itself and to check for safe area, ToolTip calls CCoreServices::GetTextElementBoundingRect that finally leads to CTextElement::GetTextPointer, that returns E_NOT_SUPPORTED whenever it fails to retrieve its parent.

This is quite easy to trigger in scenarios where the same RichTextBlock is being recycled and its Blocks are populated from code behind (ie within a ListView.ItemTemplate)

The workaround is to keep track of all the visible hyperlinks and to manually set their tooltip to null before cleaning the RichTextBlock blocks.

Steps to reproduce the bug

Minimal repro, run, move the cursor to "Here", wait for the tooltip to appear, click the link.
When moving the mouse, the app will crash.

<RichTextBlock x:Name="Block"/>
public MainPage()
{
    InitializeComponent();
    Populate();
}

private void Populate()
{
    var hyperlink = new Hyperlink();
    hyperlink.Inlines.Add(new Run
    {
        Text = "Here"
    };
    
    hyperlink.Click += (s, args) => Populate();
    
    ToolTipService.SetToolTip(hyperlink. "ToolTip");
    
    var paragraph = new Paragraph();
    paragraph.Inlines.Add(hyperlink);
    
    Block.Blocks.Clear();
    Block.Blocks.Add(paragraph);
}

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.4.4: 1.4.231219000

Windows version

No response

Additional context

No response

@FrayxRulez FrayxRulez added the bug Something isn't working label Jan 19, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 19, 2024
@FrayxRulez
Copy link
Author

Note that marking the unhandled exception as handled (from Application.UnhandledException) leads in the exception being thrown over and over again until the process is finally terminated.
Something that seems to work tho is to retrieve the open popups in the handler by using VisualTreeHelper and to then manually set IsOpen = false for the ToolTip contained in the Popup from the collection.

@bpulliam bpulliam added area-ToolTip team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ToolTip bug Something isn't working team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

2 participants