Disabled ContextMenu controls never close
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use `dotnet --info`)
```text
.NET SDK (reflecting any global.json):
Version: 5.0.202
Commit: db7cc87d51
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.202\
Host (useful for support):
Version: 5.0.5
Commit: 2f740adc14
```
* Windows version: (`winver`)

* Does the bug reproduce also in WPF for .NET Framework 4.8?:
Yes
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)?
No
**Problem description:**
Disabled ContextMenu controls never disappear.
**Actual behavior:**
If you have a ContextMenu element that is disabled either explicitly or via bindings, it will appear on right-click or menu key press, but it will not close when clicking outside the menu or hitting escape.
Interestingly, while the menu will not move if you right-click subsequent times in the same control at different locations, alternating between menu key press and right-click will re-position the menu.
The problem is exacerbated for menus in transitory views that are swapped in and out based upon user input - e.g., a content presenter displaying templated views based upon selection in a list view or grid. The context menu remains even after the parent view is removed, allowing you to build up a large number of dead context menus by opening a menu in one view, then switching to another, and repeating the process.
It is worth noting, however, that all problem context menus close when you focus a different application or close the problem application.
**Expected behavior:**
Normally, when clicking outside a context menu, it closes.
**Minimal repro:**
I added a project which adds disabled context menus to a TextBox, DataGrid, and two StackPanel controls in data templates that are displayed on a ContentPresenter when selecting items in the DataGrid.
[testdisabledmenu.zip](https://github.com/dotnet/wpf/files/6352593/testdisabledmenu.zip)
Contributor guide
Assessment
This issue has not been assessed yet.