Opening a Popup or ToolTip causes AutomationPeers to be created
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: Not relevant as it happens in all .NET versions
* Windows version: Windows 11 (but happens on all OS versions)
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
**Problem description:**
After the first `Popup` (or `ToolTip`) is opened WPF starts creating `AutomationPeer`s and starts firing automation events, even if no automation client is listening.
This massively degrades performance, especially in `DataGrid` or when a lot of controls are present/created.
This is caused by `ForceMsaaToUiaBridge` in `Popup` https://github.com/dotnet/wpf/blob/1bc136f003f0879686f53a47f984c7809b183014/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs#L3451
In addition to this:
What's also quite expensive is that the default value for `AutomationProperties.ItemStatusProperty` is `string.Empty` and the default value for `_itemStatus` in `AutomationPeer` is `null`.
This causes change notifications being sent for `AutomationElementIdentifiers.ItemStatusProperty` for every `AutomationPeer` that gets created. Why also consumes a lot of CPU cycles. Applying a hack which changes the default value for `AutomationProperties.ItemStatusProperty` to `null` cuts down the time spent raising pointless change notifications in half.
**Actual behavior:**
`AutomationPeer`s get created after first `Popup` is opened.
**Expected behavior:**
`AutomationPeer`s are only created when an automation client is present.
**Minimal repro:**
1. Create a new WPF application
2. Add a control with a tooltip
3. Hover over control to make tooltip visible
4. `AutomationPeer`s get created
Contributor guide
Assessment
This issue has not been assessed yet.