Skip to content

DropDownButton ContetMenu placement is hardcoded. #1527

@xlsupport

Description

@xlsupport

Describe the bug

A DropDownButton will always show its flyout with ContextMenu.Placement="Bottom".

Expected WPF design would use a default of "Bottom" (via MetaData or Control Template) but allow a developer to set a different Placement on the ContextMenu in Content.

Cause: The (protected) OnClick event handler.

protected override void OnClick()
 {
     base.OnClick();

     if (_contextMenu is null)
     {
         return;
     }

     _contextMenu.SetCurrentValue(MinWidthProperty, ActualWidth);
     _contextMenu.SetCurrentValue(ContextMenu.PlacementTargetProperty, this);
     _contextMenu.SetCurrentValue(
         ContextMenu.PlacementProperty,
         System.Windows.Controls.Primitives.PlacementMode.Bottom
     );
     _contextMenu.SetCurrentValue(ContextMenu.IsOpenProperty, true);
 }

It's bad practice. Please improve.

To Reproduce

Example: A window with a single DropDownButton with VerticalAlignment=Bottom: Flyout appears outside the window. (Until Wpf.Core detects the monitor Edge and reposition it.)

Expected behavior

Respect the (optional) Placement in the ContextMenu.

<ui:DropDownButton>
    <ui:DropDownButton.Flyout>
        <ContextMenu Placement="Top">

Screenshots

No response

OS version

win11

.NET version

net 10

WPF-UI NuGet version

4.0.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions