dotnet / dotnet/wpf

If tooltip is closed from code behind it still "thinks" that it occupies its rect

Open
#11,037 0 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

In our app we use tooltips extensively. Given the requirements, we have to sometimes manually manipulate tooltips from code behid by openning and closing them. As it turned out, tooltips become shamefully broken when you touch their `IsOpen` property. This is one of such bugs that can clearly be reproduced in a minimalistic setup

### Reproduction Steps

1. Create a default WPF app
2. Content of `MainWidow.xaml` (this is just to make a tooltip with somewhat decent area so that wrong behavior is more visible):
```xaml






Test




```
3. Content of `MainWindow.xaml.cs`:
```cs
using System.Windows;
using System.Windows.Controls;

namespace TestWPFTooltips;

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private async void ToolTip_Opened(object sender, RoutedEventArgs e)
{
await Task.Delay(3000);

var tooltip = (ToolTip)sender;

if (tooltip.IsOpen)
{
tooltip.IsOpen = false;
}
}
}
```

### Expected behavior

When a tooltip is closed from code behind it continues behaving as usual so that closing from code behind and closing from "natural" behavior is the same thing

### Actual behavior

After the tooltip is closed from code behind it still "thinks" it occupies its rea, so that when you move your mouse over that area and return to the target element tooltip is not automatically opened again. However, if you move your mouse somewhere else and return to the target element the tooltip is opened correctly:

![Image](https://github.com/user-attachments/assets/7ae0cc68-aeb1-464c-b9fd-14acb7563b73)

### Regression?

Tested on .NET 8, 9 and 10 P6, so probably not (we are not interested in .NET Framework behavior since our app is running on .NET 8)

### Known Workarounds

On the tooltip target subscribe to `MouseEnter` and `MouseLeave` events and open/close tooltip manually from code behind to restore built-in behavior

### Impact

I have to waste my dev time to fix basic UI behavior instead of focusing on product-related features

### Configuration

.NET 8/9/10P6
Windows 10 22H2 19045.5371 x64
I don't think this is tied to the OS/CPU architecture

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.