Skip to content

Commit

Permalink
Merge pull request #10020 from workgroupengineering/features/MenuFlyo…
Browse files Browse the repository at this point in the history
…ut/ItemContainerTheme

feat(MenuFlyout):  Add ItemContainerTheme
  • Loading branch information
maxkatz6 committed Jan 26, 2023
2 parents 594dc91 + caa2911 commit 30d4644
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/Avalonia.Controls/Flyouts/MenuFlyout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Metadata;
using Avalonia.Styling;

namespace Avalonia.Controls
{
Expand All @@ -27,6 +28,12 @@ public MenuFlyout()
AvaloniaProperty.RegisterDirect<MenuFlyout, IDataTemplate?>(nameof(ItemTemplate),
x => x.ItemTemplate, (x, v) => x.ItemTemplate = v);

/// <summary>
/// Defines the <see cref="ItemContainerTheme"/> property.
/// </summary>
public static readonly StyledProperty<ControlTheme?> ItemContainerThemeProperty =
ItemsControl.ItemContainerThemeProperty.AddOwner<MenuFlyout>();

public Classes FlyoutPresenterClasses => _classes ??= new Classes();

/// <summary>
Expand All @@ -48,6 +55,15 @@ public IDataTemplate? ItemTemplate
set => SetAndRaise(ItemTemplateProperty, ref _itemTemplate, value);
}

/// <summary>
/// Gets or sets the <see cref="ControlTheme"/> that is applied to the container element generated for each item.
/// </summary>
public ControlTheme? ItemContainerTheme
{
get { return GetValue(ItemContainerThemeProperty); }
set { SetValue(ItemContainerThemeProperty, value); }
}

private Classes? _classes;
private IEnumerable? _items;
private IDataTemplate? _itemTemplate;
Expand All @@ -57,7 +73,8 @@ protected override Control CreatePresenter()
return new MenuFlyoutPresenter
{
[!ItemsControl.ItemsProperty] = this[!ItemsProperty],
[!ItemsControl.ItemTemplateProperty] = this[!ItemTemplateProperty]
[!ItemsControl.ItemTemplateProperty] = this[!ItemTemplateProperty],
[!ItemsControl.ItemContainerThemeProperty] = this[!ItemContainerThemeProperty],
};
}

Expand Down
1 change: 0 additions & 1 deletion src/Avalonia.Controls/Flyouts/MenuFlyoutPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Avalonia.Controls.Generators;
using Avalonia.Controls.Platform;
using Avalonia.Controls.Primitives;
using Avalonia.LogicalTree;
Expand Down

0 comments on commit 30d4644

Please sign in to comment.