Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#7803 from AvaloniaUI/contextMenu-ignore…
Browse files Browse the repository at this point in the history
…s-styles-on-first-open

Fix "ContextMenu ignores styles on first open"
  • Loading branch information
maxkatz6 authored and danwalmsley committed May 10, 2022
1 parent 3941eca commit 1f9e7d0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Avalonia.Controls/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ private void Open(Control control, Control placementTarget, bool requestedByPoin
? PlacementMode.Bottom
: PlacementMode;

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

Expand Down

0 comments on commit 1f9e7d0

Please sign in to comment.