[Bug] Unable to modify the PlacementProperty of flyout in DropDownButton
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I tried to modify the Placement property on the <ContextMenu Placement="Top"> in xaml, but it didn't take effect.
Here is the complete code:
<ui:DropDownButton Content="Hello" Icon="{ui:SymbolIcon Fluent24}">
<ui:DropDownButton.Flyout>
<ContextMenu Placement="Top">
<MenuItem Header="Add" />
<MenuItem Header="Remove" />
</ContextMenu>
</ui:DropDownButton.Flyout>
</ui:DropDownButton>
After checking, I found that there is such code in DropDownButtons.cs
private void OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
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);
}
Maybe
_contextMenu.SetCurrentValue(
ContextMenu.PlacementProperty,
System.Windows.Controls.Primitives.PlacementMode.Bottom
);
should be removed or modified.
To Reproduce
Define a DropDownButton in the xaml file and modify the placement of Flyout.
Sample code:
<ui:DropDownButton Content="Hello">
<ui:DropDownButton.Flyout>
<ContextMenu Placement="Top">
<MenuItem Header="Add" />
<MenuItem Header="Remove" />
</ContextMenu>
</ui:DropDownButton.Flyout>
</ui:DropDownButton>
Expected behavior
The placement property of flyout can be modified through xaml.
Screenshots
No response
OS version
Windows 11 Pro 25H2, build 26200.7922
.NET version
.net framework 4.8.1
WPF-UI NuGet version
WPFUI 4.2.0
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open DropDownButtons.cs and inspect OnPreviewMouseLeftButtonUp, where the flyout placement is set before it opens. Reproduce the provided DropDownButton and ContextMenu Placement="Top" example, then verify that the XAML placement is honored while the button still opens with its expected sizing and target.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100