Browse Source

add content template to flyout (#18361)

pull/18385/head
Emmanuel Hansen 2 years ago
committed by GitHub
parent
commit
603a2bdb43
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 25
      src/Avalonia.Controls/Flyouts/Flyout.cs

25
src/Avalonia.Controls/Flyouts/Flyout.cs

@ -1,5 +1,6 @@
using System.ComponentModel; using System.ComponentModel;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Metadata; using Avalonia.Metadata;
using Avalonia.Styling; using Avalonia.Styling;
@ -10,8 +11,14 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Defines the <see cref="Content"/> property /// Defines the <see cref="Content"/> property
/// </summary> /// </summary>
public static readonly StyledProperty<object> ContentProperty = public static readonly StyledProperty<object?> ContentProperty =
AvaloniaProperty.Register<Flyout, object>(nameof(Content)); 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; private Classes? _classes;
@ -39,17 +46,27 @@ namespace Avalonia.Controls
/// Gets or sets the content to display in this flyout /// Gets or sets the content to display in this flyout
/// </summary> /// </summary>
[Content] [Content]
public object Content public object? Content
{ {
get => GetValue(ContentProperty); get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value); 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() protected override Control CreatePresenter()
{ {
return new FlyoutPresenter return new FlyoutPresenter
{ {
[!ContentControl.ContentProperty] = this[!ContentProperty] [!ContentControl.ContentProperty] = this[!ContentProperty],
[!ContentControl.ContentTemplateProperty] = this[!ContentTemplateProperty]
}; };
} }

Loading…
Cancel
Save