I am trying to add nested (sub) menu items. The main menu items are showing but not the sub ones. Clearly I am missing a property, but can't figure it out. Any pointers will be greatly appreciated.
Also tried adding the sub menu items to a ContextMenu then adding that to the MenuItem ContextMenu property, but that doesn't work either.
Private Function ReturnContexMenu() As ContextMenu
Try
Dim FlagMI As New MenuItem
With FlagMI
.Header = "Quick Flag"
.Name = "FlagMI"
End With
RegisterControl(Inbox_Grid, FlagMI)
Dim MarkReadMI As New MenuItem
With MarkReadMI
.Header = "Mark as read"
.Name = "MarkReadMI"
End With
RegisterControl(Inbox_Grid, MarkReadMI)
Dim MarkUnreadMI As New MenuItem
With MarkUnreadMI
.Header = "Mark as unread"
.Name = "MarkUnreadMI"
End With
RegisterControl(Inbox_Grid, MarkUnreadMI)
Dim MarkAsMI As New MenuItem
With MarkAsMI
.Header = "Mark as "
.Items.Add(MarkReadMI)
.Items.Add(MarkUnreadMI)
End With
Dim vMainContext As New ContextMenu
With vMainContext
.Name = "MainContextMenu"
.Items.Add(FlagMI)
.Items.Add(MarkAsMI)
End With
Return vMainContext
Catch ex As Exception
EmailError(ex)
Return Nothing
End Try
End Function
==========UPDATED==================
As you can see from the screenshot the sub menu items are not showing! Also tried this with a button and the same result. Could this be an issue with.NET 8? - Nope! Same problem with .NET 4.8 using a button.

After figuring out that the issue disappears after removing the reference to a 3rd party control library, we can conclude that the library is changing the default layout by providing an implicit
Style.This
Styleseems to remove the items host for the child items, which is the reason that the subitems of theMenuItemare not rendered anymore.Making use of the knowledge about the dependency property precedence list we know we can prevent any implicit
Stylefrom being applied by setting a local value e.g.nullorNothing. This way theMenuItemis forced to use its defaultStyle.VB.NET
C#