Skip to content

Disabled ToolstripMenuItems are no longer highlighted #13344

Closed
@koszeggy

Description

@koszeggy

.NET version

The changed behavior exists in .NET 8 and 9

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Works up to version .NET 7

Issue description

Disclaimer: I'm aware of the lot of ToolStrip rendering/DPI handling differences and issues across the different versions, but I'm able to manage them with a derived control. This latest breaking change is just something I really would like to let fixed in the original sources.

In .NET Framework and in .NET Core 3.0 - .NET 7. it was possible to customize the rendering of a disabled ToolStripMenuItem, because the mouse hot tracking worked even for disabled items:

ToolStripCorrectLight.gif

With some custom renderer it allowed me imitate the Window's dark theme the same way as context menus work.

In the bottom that's a multiline TextBox and its context menu, wheres at the top that's my customized ToolStrip:
ToolStripCorrectDark.gif

But starting with .NET 8 this behavior is broken:
Image

Steps to reproduce

Create a ToolStrip with a drop-down button and some ToolStripMenuItems. Set the Enabled property of a menu item to false.

Analysis

It seems the issue originates in the ToolStripItem.CanSelect property. In .NET 7 it used to return just true, whereas starting with .NET 8 it returns the value of the Enabled property.

Known Workaround

Actually the workaround is easier than some of the high DPI fixes I already applied for the older frameworks, but creating a derived FixedToolStripMenuItem and replacing every menu item in the project is really inconvenient, not mentioning that it kills the designer experience as it continues to create non-derived menu items. Therefore, I really wish this was fixed in the original source.

Proposed fix:

public class ToolStrip
{
+    public bool HotTrackDisabledItems { get; set; } = true; // initialized to true for compatibility reasons
}

public class ToolStripItem
{
-    public virtual bool CanSelect => Enabled;
+   public virtual bool CanSelect => Enabled || Owner?.HotTrackDisabledItems == true;
}

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions