Skip to content

Add ContentTemplate property to flyout #18361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/Avalonia.Controls/Flyouts/Flyout.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Metadata;
using Avalonia.Styling;

Expand All @@ -10,8 +11,14 @@ public class Flyout : PopupFlyoutBase
/// <summary>
/// Defines the <see cref="Content"/> property
/// </summary>
public static readonly StyledProperty<object> ContentProperty =
AvaloniaProperty.Register<Flyout, object>(nameof(Content));
public static readonly StyledProperty<object?> ContentProperty =
AvaloniaProperty.Register<Flyout, object?>(nameof(Content));

/// <summary>
/// Defines the <see cref="ContentTemplate"/> property.
/// </summary>
public static readonly StyledProperty<IDataTemplate?> ContentTemplateProperty =
AvaloniaProperty.Register<Flyout, IDataTemplate?>(nameof(ContentTemplate));

private Classes? _classes;

Expand Down Expand Up @@ -39,17 +46,27 @@ public ControlTheme? FlyoutPresenterTheme
/// Gets or sets the content to display in this flyout
/// </summary>
[Content]
public object Content
public object? Content
{
get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

/// <summary>
/// Gets or sets the data template used to display the content of the flyout.
/// </summary>
public IDataTemplate? ContentTemplate
{
get => GetValue(ContentTemplateProperty);
set => SetValue(ContentTemplateProperty, value);
}

protected override Control CreatePresenter()
{
return new FlyoutPresenter
{
[!ContentControl.ContentProperty] = this[!ContentProperty]
[!ContentControl.ContentProperty] = this[!ContentProperty],
[!ContentControl.ContentTemplateProperty] = this[!ContentTemplateProperty]
};
}

Expand Down
Loading