Skip to content

Commit

Permalink
fix: fix menu root find in popup.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitism committed Jun 23, 2023
1 parent 12da057 commit b69f118
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Ursa/Controls/Navigation/NavigationMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ private void OnIsClosedChanged(AvaloniaPropertyChangedEventArgs args)
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
_rootMenu = this.FindAncestorOfType<NavigationMenu>();

}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
GetRootMenu();
if (ItemTemplate == null && _rootMenu?.ItemTemplate != null)
{
SetCurrentValue(ItemTemplateProperty, _rootMenu.ItemTemplate);
Expand All @@ -98,6 +104,20 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Level = CalculateDistanceFromLogicalParent<NavigationMenu>(this) - 1;
}

private void GetRootMenu()
{
_rootMenu = this.FindAncestorOfType<NavigationMenu>();
if (_rootMenu is null)
{
var popupRoot = TopLevel.GetTopLevel(this) as PopupRoot;
if (popupRoot?.Parent is Popup popup)
{
Control? c = popup.PlacementTarget;
_rootMenu = c.FindAncestorOfType<NavigationMenu>();
}
}
}

protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
Expand Down

0 comments on commit b69f118

Please sign in to comment.