Dela via


FlyoutBase.ShouldConstrainToRootBounds Property

Definition

Gets or sets a value that indicates whether the flyout should be shown within the bounds of the XAML root.

public:
 property bool ShouldConstrainToRootBounds { bool get(); void set(bool value); };
bool ShouldConstrainToRootBounds();

void ShouldConstrainToRootBounds(bool value);
public bool ShouldConstrainToRootBounds { get; set; }
var boolean = flyoutBase.shouldConstrainToRootBounds;
flyoutBase.shouldConstrainToRootBounds = boolean;
Public Property ShouldConstrainToRootBounds As Boolean

Property Value

Boolean

bool

true if the flyout should be shown within the bounds of the XAML root; otherwise, false.

Windows requirements

Device family
Windows 10, version 1903 (introduced in 10.0.18362.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v8.0)

Examples

In this example, the flyout is not restricted to the root bounds by default. Therefore, the request to place the flyout below the button is honored as long as there is room for it on the display. The flyout is shown outside of the app window.

<Button Content="Button"
        VerticalAlignment="Bottom" HorizontalAlignment="Center">
    <Button.Flyout>
        <Flyout Placement="Bottom">
            <TextBlock Text="Flyout content" />
        </Flyout>
    </Button.Flyout>
</Button>
A closed app bar control

In this example, ShouldConstrainToRootBounds is set to true, so the flyout is restricted to the root bounds. Therefore, the request to place the flyout below the button is not honored, and the flyout is shown inside the app window above the button.

<Button Content="Button"
        VerticalAlignment="Bottom" HorizontalAlignment="Center">
    <Button.Flyout>
        <Flyout Placement="Bottom"
                ShouldConstrainToRootBounds="True">
            <TextBlock Text="Flyout content" />
        </Flyout>
    </Button.Flyout>
</Button>
A closed app bar control

Remarks

The default value depends on the derived type. For Flyout, the default is true. For MenuFlyout and CommandBarFlyout, the default is false.

This property is applicable only to apps running on the desktop. To check if the flyout is actually constrained to the root bounds, check the IsConstrainedToRootBounds property.

In an app running on the desktop, when this property is true, the flyout is shown within the main XAML window handle (HWND). When this property is false, the flyout is shown in its own top level HWND. In this case, the flyout might be positioned to extend beyond the main app window.

When a flyout with ShouldConstrainToRootBounds = false is first shown, it's placed in its own window and shown in that context. After it has been shown, ShouldConstrainToRootBounds cannot be set back to true.

The XAML root might be a CoreWindow, a XAML island, or an AppWindow.

Applies to

See also