mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-26 03:00:28 +08:00
Fix NavMenu memory leak
This commit is contained in:
@@ -34,12 +34,12 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
|
||||
|
||||
protected override IControlTemplate BuildControlTemplate()
|
||||
{
|
||||
return new FuncControlTemplate<NavMenuItem>((item, scope) =>
|
||||
return new FuncControlTemplate<NavMenuItem>((navMenuItem, scope) =>
|
||||
{
|
||||
// 仅仅为了把 Popup 包进来,没有其他什么作用
|
||||
var layoutWrapper = new Panel();
|
||||
var header = BuildMenuItemContent(item, scope);
|
||||
BuildExtraItem(layoutWrapper, scope);
|
||||
var header = BuildMenuItemContent(navMenuItem, scope);
|
||||
BuildExtraItem(navMenuItem, layoutWrapper, scope);
|
||||
layoutWrapper.Children.Add(header);
|
||||
return layoutWrapper;
|
||||
});
|
||||
@@ -90,12 +90,15 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
|
||||
Grid.SetColumn(iconPresenter, 0);
|
||||
iconPresenter.RegisterInNameScope(scope);
|
||||
CreateTemplateParentBinding(iconPresenter, ContentPresenter.ContentProperty, NavMenuItem.IconProperty);
|
||||
TokenResourceBinder.CreateTokenBinding(iconPresenter, Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.ItemMargin);
|
||||
TokenResourceBinder.CreateTokenBinding(iconPresenter, Layoutable.WidthProperty,
|
||||
NavMenuTokenKey.ItemIconSize);
|
||||
TokenResourceBinder.CreateTokenBinding(iconPresenter, Layoutable.HeightProperty,
|
||||
NavMenuTokenKey.ItemIconSize);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(iconPresenter,
|
||||
Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.ItemMargin));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(iconPresenter,
|
||||
Layoutable.WidthProperty,
|
||||
NavMenuTokenKey.ItemIconSize));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(iconPresenter,
|
||||
Layoutable.HeightProperty,
|
||||
NavMenuTokenKey.ItemIconSize));
|
||||
|
||||
var itemTextPresenter = new ContentPresenter
|
||||
{
|
||||
@@ -106,8 +109,9 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
|
||||
IsHitTestVisible = false
|
||||
};
|
||||
Grid.SetColumn(itemTextPresenter, 1);
|
||||
TokenResourceBinder.CreateTokenBinding(itemTextPresenter, Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.ItemMargin);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(itemTextPresenter,
|
||||
Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.ItemMargin));
|
||||
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentProperty,
|
||||
HeaderedSelectingItemsControl.HeaderProperty);
|
||||
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentTemplateProperty,
|
||||
@@ -123,8 +127,9 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
Grid.SetColumn(inputGestureText, 2);
|
||||
TokenResourceBinder.CreateTokenBinding(inputGestureText, Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.ItemMargin);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(inputGestureText,
|
||||
Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.ItemMargin));
|
||||
CreateTemplateParentBinding(inputGestureText,
|
||||
SingleLineText.TextProperty,
|
||||
NavMenuItem.InputGestureProperty,
|
||||
@@ -133,7 +138,7 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
|
||||
|
||||
inputGestureText.RegisterInNameScope(scope);
|
||||
|
||||
var menuIndicatorIcon = BuildMenuIndicatorIcon(scope);
|
||||
var menuIndicatorIcon = BuildMenuIndicatorIcon(navMenuItem, scope);
|
||||
Grid.SetColumn(menuIndicatorIcon, 3);
|
||||
|
||||
layout.Children.Add(iconPresenter);
|
||||
@@ -143,11 +148,11 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
|
||||
return layout;
|
||||
}
|
||||
|
||||
protected virtual void BuildExtraItem(Panel layout, INameScope scope)
|
||||
protected virtual void BuildExtraItem(NavMenuItem navMenuItem, Panel layout, INameScope scope)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual Control BuildMenuIndicatorIcon(INameScope scope)
|
||||
protected virtual Control BuildMenuIndicatorIcon(NavMenuItem navMenuItem, INameScope scope)
|
||||
{
|
||||
var menuIndicatorIcon = AntDesignIconPackage.RightOutlined();
|
||||
menuIndicatorIcon.Name = MenuIndicatorIconPart;
|
||||
@@ -156,10 +161,12 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
|
||||
|
||||
CreateTemplateParentBinding(menuIndicatorIcon, Icon.IsEnabledProperty, NavMenuItem.IsEnabledProperty);
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(menuIndicatorIcon, Layoutable.WidthProperty,
|
||||
NavMenuTokenKey.MenuArrowSize);
|
||||
TokenResourceBinder.CreateTokenBinding(menuIndicatorIcon, Layoutable.HeightProperty,
|
||||
NavMenuTokenKey.MenuArrowSize);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(menuIndicatorIcon,
|
||||
Layoutable.WidthProperty,
|
||||
NavMenuTokenKey.MenuArrowSize));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(menuIndicatorIcon,
|
||||
Layoutable.HeightProperty,
|
||||
NavMenuTokenKey.MenuArrowSize));
|
||||
menuIndicatorIcon.RegisterInNameScope(scope);
|
||||
|
||||
return menuIndicatorIcon;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
@@ -35,8 +36,8 @@ internal class HorizontalNavMenuTheme : BaseNavMenuTheme
|
||||
DockPanel.SetDock(horizontalLine, Dock.Bottom);
|
||||
CreateTemplateParentBinding(horizontalLine, Rectangle.HeightProperty,
|
||||
NavMenu.HorizontalBorderThicknessProperty);
|
||||
TokenResourceBinder.CreateTokenBinding(horizontalLine, Rectangle.FillProperty,
|
||||
SharedTokenKey.ColorBorderSecondary);
|
||||
navMenu.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(horizontalLine, Rectangle.FillProperty,
|
||||
SharedTokenKey.ColorBorderSecondary));
|
||||
|
||||
layout.Children.Add(BuildItemPresenter(true, scope));
|
||||
return layout;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AtomUI.MotionScene;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme.Styling;
|
||||
using AtomUI.Utils;
|
||||
@@ -33,9 +34,9 @@ internal class InlineNavMenuItemTheme : BaseNavMenuItemTheme
|
||||
return ID;
|
||||
}
|
||||
|
||||
protected override Control BuildMenuIndicatorIcon(INameScope scope)
|
||||
protected override Control BuildMenuIndicatorIcon(NavMenuItem navMenuItem, INameScope scope)
|
||||
{
|
||||
var indicatorIcon = base.BuildMenuIndicatorIcon(scope);
|
||||
var indicatorIcon = base.BuildMenuIndicatorIcon(navMenuItem, scope);
|
||||
var menuIndicatorIconPresenter = new Border()
|
||||
{
|
||||
Name = MenuIndicatorIconLayoutPart
|
||||
@@ -58,7 +59,8 @@ internal class InlineNavMenuItemTheme : BaseNavMenuItemTheme
|
||||
{
|
||||
Name = ChildItemsLayoutTransformPart,
|
||||
};
|
||||
TokenResourceBinder.CreateTokenBinding(childItemsLayoutTransform, MotionActorControl.MarginProperty,
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(childItemsLayoutTransform,
|
||||
MotionActorControl.MarginProperty,
|
||||
NavMenuTokenKey.VerticalItemsPanelSpacing, BindingPriority.Template,
|
||||
(v) =>
|
||||
{
|
||||
@@ -68,7 +70,7 @@ internal class InlineNavMenuItemTheme : BaseNavMenuItemTheme
|
||||
}
|
||||
|
||||
return new Thickness();
|
||||
});
|
||||
}));
|
||||
childItemsLayoutTransform.RegisterInNameScope(scope);
|
||||
|
||||
var itemsPresenter = new ItemsPresenter
|
||||
@@ -95,7 +97,7 @@ internal class InlineNavMenuItemTheme : BaseNavMenuItemTheme
|
||||
Indent = navMenuItem.InlineItemIndentUnit
|
||||
};
|
||||
CreateTemplateParentBinding(infoGrid, Grid.MarginProperty,
|
||||
NavMenuItem.LevelProperty,
|
||||
NavMenuItem.LevelProperty,
|
||||
BindingMode.OneWay,
|
||||
indentConverter);
|
||||
|
||||
@@ -117,20 +119,23 @@ internal class InlineNavMenuItemTheme : BaseNavMenuItemTheme
|
||||
{
|
||||
{
|
||||
// 动画设置
|
||||
var isMotionEnabledStyle = new Style(selector => selector.Nesting().PropertyEquals(NavMenuItem.IsMotionEnabledProperty, true));
|
||||
var isMotionEnabledStyle = new Style(selector =>
|
||||
selector.Nesting().PropertyEquals(NavMenuItem.IsMotionEnabledProperty, true));
|
||||
var menuIndicatorStyle =
|
||||
new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconLayoutPart));
|
||||
menuIndicatorStyle.Add(Border.TransitionsProperty, new SetterValueFactory<Transitions>(() => new Transitions()
|
||||
{
|
||||
AnimationUtils.CreateTransition<TransformOperationsTransition>(ContentPresenter.RenderTransformProperty)
|
||||
}));
|
||||
menuIndicatorStyle.Add(Border.TransitionsProperty, new SetterValueFactory<Transitions>(() =>
|
||||
new Transitions
|
||||
{
|
||||
AnimationUtils.CreateTransition<TransformOperationsTransition>(ContentPresenter
|
||||
.RenderTransformProperty)
|
||||
}));
|
||||
isMotionEnabledStyle.Add(menuIndicatorStyle);
|
||||
Add(isMotionEnabledStyle);
|
||||
}
|
||||
{
|
||||
var menuIndicatorStyle =
|
||||
new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconLayoutPart));
|
||||
|
||||
|
||||
menuIndicatorStyle.Add(Border.RenderTransformProperty, new SetterValueFactory<ITransform>(() =>
|
||||
{
|
||||
var transformOptions = new TransformOperations.Builder(1);
|
||||
@@ -144,7 +149,7 @@ internal class InlineNavMenuItemTheme : BaseNavMenuItemTheme
|
||||
{
|
||||
var menuIndicatorStyle =
|
||||
new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconLayoutPart));
|
||||
|
||||
|
||||
menuIndicatorStyle.Add(Border.RenderTransformProperty, new SetterValueFactory<ITransform>(() =>
|
||||
{
|
||||
var transformOptions = new TransformOperations.Builder(1);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using System.Windows.Input;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows.Input;
|
||||
using AtomUI.Controls.Utils;
|
||||
using AtomUI.Data;
|
||||
using AtomUI.IconPkg;
|
||||
using AtomUI.Input;
|
||||
using AtomUI.Media;
|
||||
using AtomUI.MotionScene;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia;
|
||||
@@ -32,7 +34,8 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
ISelectable,
|
||||
ICommandSource,
|
||||
IClickableControl,
|
||||
ICustomHitTest
|
||||
ICustomHitTest,
|
||||
ITokenResourceConsumer
|
||||
{
|
||||
public const string TopLevelPC = ":toplevel";
|
||||
public const string SeparatorPC = ":separator";
|
||||
@@ -370,6 +373,7 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
set => SetAndRaise(IsMotionEnabledProperty, ref _isMotionEnabled, value);
|
||||
}
|
||||
|
||||
CompositeDisposable? ITokenResourceConsumer.TokenBindingsDisposable => _tokenBindingsDisposable;
|
||||
#endregion
|
||||
|
||||
#region 公共事件定义
|
||||
@@ -466,13 +470,13 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
private static readonly FuncTemplate<Panel?> DefaultPanel =
|
||||
new(() => new StackPanel());
|
||||
|
||||
private CompositeDisposable? _tokenBindingsDisposable;
|
||||
private bool _commandCanExecute = true;
|
||||
private bool _commandBindingError;
|
||||
private Popup? _popup;
|
||||
private KeyGesture? _hotkey;
|
||||
private bool _isEmbeddedInMenu;
|
||||
private Border? _horizontalFrame;
|
||||
private IDisposable? _itemContainerThemeDisposable;
|
||||
private MotionActorControl? _childItemsLayoutTransform;
|
||||
private Border? _headerFrame;
|
||||
private bool _animating = false;
|
||||
@@ -571,6 +575,7 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
}
|
||||
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
_tokenBindingsDisposable = new CompositeDisposable();
|
||||
|
||||
Level = CalculateDistanceFromLogicalParent<NavMenu>(this) - 1;
|
||||
|
||||
@@ -590,8 +595,10 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
}
|
||||
|
||||
_isEmbeddedInMenu = parent?.FindLogicalAncestorOfType<INavMenu>(true) != null;
|
||||
TokenResourceBinder.CreateTokenBinding(this, InlineItemIndentUnitProperty,
|
||||
NavMenuTokenKey.InlineItemIndentUnit);
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, InlineItemIndentUnitProperty,
|
||||
NavMenuTokenKey.InlineItemIndentUnit));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, PopupMinWidthProperty,
|
||||
NavMenuTokenKey.MenuPopupMinWidth));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -617,6 +624,7 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
{
|
||||
Command.CanExecuteChanged -= CanExecuteChangedHandler;
|
||||
}
|
||||
this.DisposeTokenBindings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -702,7 +710,7 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
}
|
||||
|
||||
_horizontalFrame = e.NameScope.Find<Border>(TopLevelHorizontalNavMenuItemTheme.FramePart);
|
||||
TokenResourceBinder.CreateTokenBinding(this, PopupMinWidthProperty, NavMenuTokenKey.MenuPopupMinWidth);
|
||||
|
||||
SetupItemIcon();
|
||||
if (Mode == NavMenuMode.Inline)
|
||||
{
|
||||
@@ -713,8 +721,8 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
_childItemsLayoutTransform.SetCurrentValue(MotionActorControl.IsVisibleProperty, IsSubMenuOpen);
|
||||
}
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(this, OpenCloseMotionDurationProperty,
|
||||
SharedTokenKey.MotionDurationSlow);
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, OpenCloseMotionDurationProperty,
|
||||
SharedTokenKey.MotionDurationSlow));
|
||||
}
|
||||
SetupTransitions();
|
||||
}
|
||||
@@ -936,35 +944,35 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
|
||||
private void SetupItemIcon()
|
||||
{
|
||||
if (Icon is Icon menuItemIcon)
|
||||
if (Icon is not null)
|
||||
{
|
||||
BindUtils.RelayBind(this, IsEnabledProperty, menuItemIcon, Icon.IsEnabledProperty);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.WidthProperty,
|
||||
NavMenuTokenKey.ItemIconSize);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.HeightProperty,
|
||||
NavMenuTokenKey.ItemIconSize);
|
||||
BindUtils.RelayBind(this, IsEnabledProperty, Icon, Icon.IsEnabledProperty);
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.WidthProperty,
|
||||
NavMenuTokenKey.ItemIconSize));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.HeightProperty,
|
||||
NavMenuTokenKey.ItemIconSize));
|
||||
|
||||
if (IsDarkStyle)
|
||||
{
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.NormalFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemColor);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.SelectedFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemSelectedColor);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.ActiveFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemHoverColor);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.DisabledFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemDisabledColor);
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.NormalFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemColor));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.SelectedFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemSelectedColor));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.ActiveFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemHoverColor));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.DisabledFilledBrushProperty,
|
||||
NavMenuTokenKey.DarkItemDisabledColor));
|
||||
}
|
||||
else
|
||||
{
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.NormalFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemColor);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.SelectedFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemSelectedColor);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.ActiveFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemHoverColor);
|
||||
TokenResourceBinder.CreateTokenBinding(menuItemIcon, Icon.DisabledFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemDisabledColor);
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.NormalFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemColor));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.SelectedFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemSelectedColor));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.ActiveFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemHoverColor));
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(Icon, Icon.DisabledFilledBrushProperty,
|
||||
NavMenuTokenKey.ItemDisabledColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1237,12 +1245,10 @@ public class NavMenuItem : HeaderedSelectingItemsControl,
|
||||
{
|
||||
if (ItemContainerTheme is null || force)
|
||||
{
|
||||
_itemContainerThemeDisposable?.Dispose();
|
||||
if (Mode == NavMenuMode.Inline)
|
||||
{
|
||||
_itemContainerThemeDisposable =
|
||||
TokenResourceBinder.CreateTokenBinding(this, ItemContainerThemeProperty,
|
||||
InlineNavMenuItemTheme.ID);
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, ItemContainerThemeProperty,
|
||||
InlineNavMenuItemTheme.ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
@@ -24,14 +25,14 @@ internal class NavMenuItemTheme : BaseNavMenuItemTheme
|
||||
{
|
||||
}
|
||||
|
||||
protected override void BuildExtraItem(Panel layout, INameScope scope)
|
||||
protected override void BuildExtraItem(NavMenuItem navMenuItem, Panel layout, INameScope scope)
|
||||
{
|
||||
var popup = CreateMenuPopup();
|
||||
var popup = CreateMenuPopup(navMenuItem);
|
||||
popup.RegisterInNameScope(scope);
|
||||
layout.Children.Add(popup);
|
||||
}
|
||||
|
||||
protected Popup CreateMenuPopup()
|
||||
protected Popup CreateMenuPopup(NavMenuItem navMenuItem)
|
||||
{
|
||||
var popup = new Popup
|
||||
{
|
||||
@@ -46,18 +47,23 @@ internal class NavMenuItemTheme : BaseNavMenuItemTheme
|
||||
Name = PopupFramePart
|
||||
};
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty,
|
||||
NavMenuTokenKey.TopLevelItemPopupMarginToAnchor);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.CornerRadiusProperty,
|
||||
NavMenuTokenKey.MenuPopupBorderRadius);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Layoutable.MinWidthProperty,
|
||||
NavMenuTokenKey.MenuPopupMinWidth);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Layoutable.MaxWidthProperty,
|
||||
NavMenuTokenKey.MenuPopupMaxWidth);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Layoutable.MaxHeightProperty,
|
||||
NavMenuTokenKey.MenuPopupMaxHeight);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Decorator.PaddingProperty,
|
||||
NavMenuTokenKey.MenuPopupContentPadding);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(popup,
|
||||
Popup.MarginToAnchorProperty,
|
||||
NavMenuTokenKey.TopLevelItemPopupMarginToAnchor));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border,
|
||||
Border.CornerRadiusProperty,
|
||||
NavMenuTokenKey.MenuPopupBorderRadius));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border,
|
||||
Layoutable.MinWidthProperty,
|
||||
NavMenuTokenKey.MenuPopupMinWidth));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border,
|
||||
Layoutable.MaxWidthProperty,
|
||||
NavMenuTokenKey.MenuPopupMaxWidth));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border,
|
||||
Layoutable.MaxHeightProperty,
|
||||
NavMenuTokenKey.MenuPopupMaxHeight));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Decorator.PaddingProperty,
|
||||
NavMenuTokenKey.MenuPopupContentPadding));
|
||||
|
||||
var scrollViewer = new MenuScrollViewer();
|
||||
var itemsPresenter = new ItemsPresenter
|
||||
@@ -71,10 +77,11 @@ internal class NavMenuItemTheme : BaseNavMenuItemTheme
|
||||
|
||||
popup.Child = border;
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty,
|
||||
NavMenuTokenKey.TopLevelItemPopupMarginToAnchor);
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty,
|
||||
NavMenuTokenKey.MenuPopupBoxShadows);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(popup,
|
||||
Popup.MarginToAnchorProperty,
|
||||
NavMenuTokenKey.TopLevelItemPopupMarginToAnchor));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty,
|
||||
NavMenuTokenKey.MenuPopupBoxShadows));
|
||||
CreateTemplateParentBinding(popup, Popup.IsOpenProperty,
|
||||
NavMenuItem.IsSubMenuOpenProperty, BindingMode.TwoWay);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ internal class NavMenuTheme : BaseControlTheme
|
||||
|
||||
protected override IControlTemplate BuildControlTemplate()
|
||||
{
|
||||
return new FuncControlTemplate<NavMenu>((menu, scope) =>
|
||||
return new FuncControlTemplate<NavMenu>((navMenu, scope) =>
|
||||
{
|
||||
var itemPresenter = new ItemsPresenter
|
||||
{
|
||||
@@ -47,8 +47,8 @@ internal class NavMenuTheme : BaseControlTheme
|
||||
CreateTemplateParentBinding(horizontalLine, Rectangle.IsVisibleProperty, NavMenu.ModeProperty,
|
||||
BindingMode.Default,
|
||||
new FuncValueConverter<NavMenuMode, bool>(v => v == NavMenuMode.Horizontal));
|
||||
TokenResourceBinder.CreateTokenBinding(horizontalLine, Rectangle.FillProperty,
|
||||
SharedTokenKey.ColorBorderSecondary);
|
||||
navMenu.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(horizontalLine, Rectangle.FillProperty,
|
||||
SharedTokenKey.ColorBorderSecondary));
|
||||
|
||||
var border = new Border
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ internal class TopLevelHorizontalNavMenuItemTheme : BaseControlTheme
|
||||
LastChildFill = true
|
||||
};
|
||||
|
||||
var popup = CreateMenuPopup();
|
||||
var popup = CreateMenuPopup(menuItem);
|
||||
popup.RegisterInNameScope(scope);
|
||||
contentLayout.Children.Add(popup);
|
||||
|
||||
@@ -77,8 +77,8 @@ internal class TopLevelHorizontalNavMenuItemTheme : BaseControlTheme
|
||||
CreateTemplateParentBinding(iconPresenter, ContentPresenter.IsVisibleProperty, NavMenuItem.IconProperty,
|
||||
BindingMode.Default,
|
||||
ObjectConverters.IsNotNull);
|
||||
TokenResourceBinder.CreateTokenBinding(iconPresenter, Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.IconMargin);
|
||||
menuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(iconPresenter, Layoutable.MarginProperty,
|
||||
NavMenuTokenKey.IconMargin));
|
||||
|
||||
contentLayout.Children.Add(iconPresenter);
|
||||
|
||||
@@ -140,7 +140,7 @@ internal class TopLevelHorizontalNavMenuItemTheme : BaseControlTheme
|
||||
});
|
||||
}
|
||||
|
||||
private Popup CreateMenuPopup()
|
||||
private Popup CreateMenuPopup(NavMenuItem navMenuItem)
|
||||
{
|
||||
var popup = new Popup
|
||||
{
|
||||
@@ -154,20 +154,20 @@ internal class TopLevelHorizontalNavMenuItemTheme : BaseControlTheme
|
||||
|
||||
CreateTemplateParentBinding(border, Border.MinWidthProperty, NavMenuItem.EffectivePopupMinWidthProperty);
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.BackgroundProperty,
|
||||
SharedTokenKey.ColorBgContainer);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Border.CornerRadiusProperty,
|
||||
MenuTokenKey.MenuPopupBorderRadius);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Layoutable.MinWidthProperty,
|
||||
MenuTokenKey.MenuPopupMinWidth);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Layoutable.MaxWidthProperty,
|
||||
MenuTokenKey.MenuPopupMaxWidth);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Layoutable.MinHeightProperty,
|
||||
MenuTokenKey.MenuPopupMinHeight);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Layoutable.MaxHeightProperty,
|
||||
MenuTokenKey.MenuPopupMaxHeight);
|
||||
TokenResourceBinder.CreateTokenBinding(border, Decorator.PaddingProperty,
|
||||
MenuTokenKey.MenuPopupContentPadding);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Border.BackgroundProperty,
|
||||
SharedTokenKey.ColorBgContainer));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Border.CornerRadiusProperty,
|
||||
MenuTokenKey.MenuPopupBorderRadius));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Layoutable.MinWidthProperty,
|
||||
MenuTokenKey.MenuPopupMinWidth));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Layoutable.MaxWidthProperty,
|
||||
MenuTokenKey.MenuPopupMaxWidth));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Layoutable.MinHeightProperty,
|
||||
MenuTokenKey.MenuPopupMinHeight));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Layoutable.MaxHeightProperty,
|
||||
MenuTokenKey.MenuPopupMaxHeight));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(border, Decorator.PaddingProperty,
|
||||
MenuTokenKey.MenuPopupContentPadding));
|
||||
|
||||
var scrollViewer = new MenuScrollViewer();
|
||||
var itemsPresenter = new ItemsPresenter
|
||||
@@ -181,10 +181,10 @@ internal class TopLevelHorizontalNavMenuItemTheme : BaseControlTheme
|
||||
border.Child = scrollViewer;
|
||||
popup.Child = border;
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty,
|
||||
MenuTokenKey.TopLevelItemPopupMarginToAnchor);
|
||||
TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty,
|
||||
MenuTokenKey.MenuPopupBoxShadows);
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty,
|
||||
MenuTokenKey.TopLevelItemPopupMarginToAnchor));
|
||||
navMenuItem.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty,
|
||||
MenuTokenKey.MenuPopupBoxShadows));
|
||||
|
||||
CreateTemplateParentBinding(popup, Popup.IsOpenProperty,
|
||||
NavMenuItem.IsSubMenuOpenProperty, BindingMode.TwoWay);
|
||||
|
||||
Reference in New Issue
Block a user