FlyoutBase
- Assembly:
Fluence.Wpf - Namespace:
Fluence.Wpf.Controls
public abstract class FlyoutBase : DependencyObject
Represents the base class for flyout controls that display lightweight UI in a light-dismiss Popup anchored to a placement target, mirroring the WinUI 3 FlyoutBase contract.
Remarks: The popup is created lazily on the first ShowAt call. It is pinned open and FlyoutBase owns the light dismiss itself: a press outside the flyout, a press on the owning window's caption or borders, the window moving, and the application losing the foreground all close it, as does Escape pressed inside it. A press on the placement target closes the flyout and is swallowed, so the button that opened it toggles it shut rather than reopening it. The popup uses a custom placement callback so the flyout is centered on the facing edge of its placement target, matching WinUI. Derived classes supply the popup child via CreatePresenter.
Base type: DependencyObject (including inherited WPF and .NET members)
Constructors
FlyoutBase
protected FlyoutBase()
Creates a new FlyoutBase instance.
Properties
IsOpen
public bool IsOpen { get; }
Gets a value indicating whether the flyout is currently open.
Placement
public FlyoutPlacementMode Placement { get; set; }
Gets or sets where the flyout opens relative to its placement target.
ShouldConstrainToRootBounds
public bool ShouldConstrainToRootBounds { get; set; }
Gets or sets a value indicating whether the flyout should stay within the bounds of the XAML root. Accepted for WinUI signature compatibility; WPF popups are positioned by the OS, so the value is not currently enforced.
Methods
CreatePresenter
protected abstract FrameworkElement CreatePresenter()
Creates the element that presents the flyout content as the popup child. Called once when the popup is created; implementations may cache and return the same instance.
Returns: The presenter element hosted as the popup child.
GetAttachedFlyout
public static FlyoutBase? GetAttachedFlyout(FrameworkElement element)
Gets the flyout attached to the specified element via AttachedFlyoutProperty.
Parameter element: The element the flyout is attached to.
Returns: The attached flyout, or null when none is attached.
Exception System.ArgumentNullException: element is null.
Hide
public void Hide()
Hides the flyout. Raises Closing first; the close is abandoned when a handler sets Cancel to true. Closed is raised once the popup has closed.
SetAttachedFlyout
public static void SetAttachedFlyout(FrameworkElement element, FlyoutBase? value)
Sets the flyout attached to the specified element via AttachedFlyoutProperty.
Parameter element: The element to attach the flyout to.
Parameter value: The flyout to attach, or null to detach.
Exception System.ArgumentNullException: element is null.
ShowAt
public void ShowAt(FrameworkElement placementTarget)
Shows the flyout placed relative to the specified element. Raises Opening before the popup opens and Opened after, then moves focus to the presenter. The presenter inherits the placement target's DataContext for the lifetime of the popup so bindings inside the flyout content resolve against the anchor's view model.
Remarks: The popup is open by the time this returns. When another element holds the mouse capture, which is the case inside a button's Click handler, the flyout takes the light-dismiss capture a second time once that gesture is over: a popup that took it mid-gesture loses it again the moment the button lets go, which closes the flyout as it appears.
Parameter placementTarget: The element to anchor the flyout to.
Exception System.ArgumentNullException: placementTarget is null.
ShowAttachedFlyout
public static void ShowAttachedFlyout(FrameworkElement flyoutOwner)
Shows the flyout attached to the specified element via AttachedFlyoutProperty, anchored to that element. Does nothing when no flyout is attached.
Parameter flyoutOwner: The element whose attached flyout should be shown.
Exception System.ArgumentNullException: flyoutOwner is null.
Events
Closed
public event EventHandler? Closed
Occurs after the flyout has closed, whether through Hide or light dismiss.
Closing
public event EventHandler<FlyoutBaseClosingEventArgs>? Closing
Occurs before the flyout closes through Hide. Set Cancel to true to keep the flyout open. Light-dismiss closes bypass this event and raise only Closed.
Opened
public event EventHandler? Opened
Occurs after the flyout has opened.
Opening
public event EventHandler? Opening
Occurs before the flyout opens.
Dependency property identifiers
Use these identifiers with WPF property APIs. The matching CLR properties appear above when the control exposes them.
AttachedFlyoutProperty
public static readonly DependencyProperty AttachedFlyoutProperty
Identifies the AttachedFlyout attached property, which associates a flyout with an arbitrary element so it can later be opened via ShowAttachedFlyout.
PlacementProperty
public static readonly DependencyProperty PlacementProperty
Identifies the Placement dependency property.
ShouldConstrainToRootBoundsProperty
public static readonly DependencyProperty ShouldConstrainToRootBoundsProperty
Identifies the ShouldConstrainToRootBounds dependency property.