| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.ComponentModel;
- using Avalonia.Controls.Primitives;
- using Avalonia.Metadata;
- using Avalonia.Styling;
- namespace Avalonia.Controls
- {
- public class Flyout : PopupFlyoutBase
- {
- /// <summary>
- /// Defines the <see cref="Content"/> property
- /// </summary>
- public static readonly StyledProperty<object> ContentProperty =
- AvaloniaProperty.Register<Flyout, object>(nameof(Content));
- private Classes? _classes;
- /// <summary>
- /// Gets the Classes collection to apply to the FlyoutPresenter this Flyout is hosting
- /// </summary>
- public Classes FlyoutPresenterClasses
- {
- get => _classes ??= new Classes();
- set
- {
- if (_classes is null)
- _classes = value;
- else if (_classes != value)
- _classes.Replace(value);
- }
- }
- /// <summary>
- /// Defines the <see cref="FlyoutPresenterTheme"/> property.
- /// </summary>
- public static readonly StyledProperty<ControlTheme?> FlyoutPresenterThemeProperty =
- AvaloniaProperty.Register<Flyout, ControlTheme?>(nameof(FlyoutPresenterTheme));
-
- /// <summary>
- /// Gets or sets the <see cref="ControlTheme"/> that is applied to the container element generated for the flyout presenter.
- /// </summary>
- public ControlTheme? FlyoutPresenterTheme
- {
- get => GetValue(FlyoutPresenterThemeProperty);
- set => SetValue(FlyoutPresenterThemeProperty, value);
- }
-
- /// <summary>
- /// Gets or sets the content to display in this flyout
- /// </summary>
- [Content]
- public object Content
- {
- get => GetValue(ContentProperty);
- set => SetValue(ContentProperty, value);
- }
- protected override Control CreatePresenter()
- {
- return new FlyoutPresenter
- {
- [!ContentControl.ContentProperty] = this[!ContentProperty]
- };
- }
- protected override void OnOpening(CancelEventArgs args)
- {
- if (Popup.Child is { } presenter)
- {
- if (_classes != null)
- {
- SetPresenterClasses(presenter, FlyoutPresenterClasses);
- }
- if (FlyoutPresenterTheme is { } theme)
- {
- presenter.SetValue(Control.ThemeProperty, theme);
- }
- }
- base.OnOpening(args);
- }
- }
- }
|