Skip to content

Commit 1f9e7d0

Browse files
maxkatz6danwalmsley
authored andcommitted
Merge pull request AvaloniaUI#7803 from AvaloniaUI/contextMenu-ignores-styles-on-first-open
Fix "ContextMenu ignores styles on first open"
1 parent 3941eca commit 1f9e7d0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Avalonia.Controls/ContextMenu.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ private void Open(Control control, Control placementTarget, bool requestedByPoin
349349
? PlacementMode.Bottom
350350
: PlacementMode;
351351

352+
//Position of the line below is really important.
353+
//All styles are being applied only when control has logical parent.
354+
//Line below will add ContextMenu as child to the Popup and this will trigger styles and they would be applied.
355+
//If you will move line below somewhere else it may cause that ContextMenu will behave differently from what you are expecting.
356+
_popup.Child = this;
352357
_popup.PlacementTarget = placementTarget;
353358
_popup.HorizontalOffset = HorizontalOffset;
354359
_popup.VerticalOffset = VerticalOffset;
@@ -357,7 +362,6 @@ private void Open(Control control, Control placementTarget, bool requestedByPoin
357362
_popup.PlacementGravity = PlacementGravity;
358363
_popup.PlacementRect = PlacementRect;
359364
_popup.WindowManagerAddShadowHint = WindowManagerAddShadowHint;
360-
_popup.Child = this;
361365
IsOpen = true;
362366
_popup.IsOpen = true;
363367

0 commit comments

Comments
 (0)