lepoco / lepoco/wpfui

MenuItem with SubmenuHeaderTemplate - Popup invalid positioning

Open
#1,322 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
9.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

The placement for the sub-items in the ContextMenu works incorrectly if the popup is displayed above the parent control. This happens because of the DropShadowEffect that is added to the child item popup and requires some offsets and margins to be aligned. This works fine in cases when the popup is placed below the parent element.

To Reproduce

I've added the following ContextMenu to the Gallery app NotifyIcon:

   <tray:NotifyIcon
        Grid.Row="0"
        FocusOnLeftClick="True"
        Icon="pack://application:,,,/Assets/wpfui.png"
        MenuOnRightClick="True"
        TooltipText="WPF UI Gallery">
        <tray:NotifyIcon.Menu>
            <ContextMenu>
                <MenuItem Header="Item 1">
                    <MenuItem Header="Item 1.1"/>
                    <MenuItem Header="Item 1.2"/>
                </MenuItem>
                <MenuItem Header="Item 2">
                    <MenuItem Header="Item 2.1"/>
                    <MenuItem Header="Item 2.2"/>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Item 3">
                </MenuItem>
            </ContextMenu>
        </tray:NotifyIcon.Menu>
    </tray:NotifyIcon>
Expected behavior

The popup should be placed right next to the MenuItem. We can achieve that by removing the DropShadowEffect and setting the VerticalOffset and Margin to 0

Screenshots

Image
Image

OS version

Win 11 24H2

.NET version

8.0

WPF-UI NuGet version

latest main branch

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Gallery app NotifyIcon ContextMenu reproduction and inspect the MenuItem submenu popup styling, especially its DropShadowEffect, VerticalOffset, and Margin. Compare positioning when the popup appears above and below the parent MenuItem. Done means the submenu popup sits directly beside its parent in both placements without the reported offset.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.