Skip to content

Match WPF behaviour when positioning popups with margin on the root element #18810

@TomEdwardsEnscape

Description

@TomEdwardsEnscape

Is your feature request related to a problem? Please describe.

The popup in this XAML snipped has dramatically different positions in WPF and XAML:

<Grid>
    <ToggleButton Name="PopupButton" VerticalAlignment="Center" HorizontalAlignment="Center">Target</ToggleButton>
    <Popup IsOpen="{Binding IsChecked, ElementName=PopupButton}" PlacementTarget="{Binding ElementName=PopupButton}" Placement="Right" AllowsTransparency="True">
        <Border Margin="40">
            <Border.Effect>
                <DropShadowEffect BlurRadius="40"  Color="Black"/>
            </Border.Effect>
            <TextBlock Background="White" Padding="6">Hello world</TextBlock>
        </Border>
    </Popup>
</Grid>

You will need to remove AllowsTransparency="True" when compiling for Avalonia.

WPF:

Image

Avalonia:

Image

WPF is positioning the popup according to only the bounds of its content, excluding the 40px margin on the root Border. This behaviour allows the user to easily add a drop shadow effect to a popup without affecting its position. The margin is still applied to the actual window and drawing surface created internally by WPF, otherwise there would be nowhere to render the drop shadow.

Avalonia on the other hand is putting the popup content into a ContentPresenter and using the presenter's bounds to position the popup, without any special behaviour. This means that the margin is included in the position calculation.

Describe the solution you'd like

Ignore the margin of the root element of a popup (or flyout) when positioning it. The margin is by definition outside the bounds of the control and is only of relevance for providing space to render visual effects like drop shadows.

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions