Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] Padding and Margin are not applied to the Popup class of Popup2 by Style attribute

Open usausa opened this issue 5 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

  • [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

Current Behavior

Margin and Padding are not applied to Popup in the Style attribute. Property, the value is applied.

Expected Behavior

Margin and Padding are applied in the Style attribute as well as in the property.

Steps To Reproduce

  1. Create a Style to be applied to the Popup and set Padding and Margin.
  2. Apply Style to Popup

by Style

<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup
    x:Class="Popup2App.NoBorderPropertyPopup"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    Style="{StaticResource NoBorderPopup}"
    WidthRequest="200">

    <toolkit:Popup.Resources>
        <ResourceDictionary>
            <Style x:Key="NoBorderPopup" TargetType="toolkit:Popup">
                <Setter Property="Padding" Value="0" />
                <Setter Property="Margin" Value="0" />
                <Setter Property="BackgroundColor" Value="Blue" />
            </Style>
        </ResourceDictionary>
    </toolkit:Popup.Resources>

    <VerticalStackLayout>
        <Button Clicked="OnCloseClick" Text="Close" />
    </VerticalStackLayout>

</toolkit:Popup>

Image

  • by Property
<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup
    x:Class="Popup2App.NoBorderStylePopup"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    Margin="0"
    Padding="0"
    BackgroundColor="Blue"
    WidthRequest="200">

    <VerticalStackLayout>
        <Button Clicked="OnCloseClick" Text="Close" />
    </VerticalStackLayout>

</toolkit:Popup>

Image

Link to public reproduction project repository

https://github.com/usausa/Issue-CommunityToolkitMaui-Popup2

Environment

- .NET MAUI CommunityToolkit: 12.0.0
- OS: Android
- .NET MAUI: 9.0.80

Anything else?

No response

usausa avatar Jun 19 '25 00:06 usausa

I can also reproduce it.

LeoJHarris avatar Jun 21 '25 05:06 LeoJHarris

Same here

ExLuzZziVo avatar Jun 23 '25 14:06 ExLuzZziVo

This is also the case with BackgroundColor, HorizontalOptions, VerticalOptions, BackgroundColor. HeightRequest and WidthRequest seem to work.

redwolf2 avatar Jun 25 '25 18:06 redwolf2

Absolutely true. There is some unnesessary Border that appears, that, in theory, should catch all properties from popup, but it doesn't.

Image

One temporary stupid workaround I found is to remove/change all you need after popup is opened.

this.Opened += popupOpenedTemporaryCrutchFix_Handler;

private void popupOpenedTemporaryCrutchFix_Handler(object? sender, EventArgs e)
{
	this.Opened -= popupOpenedTemporaryCrutchFix_Handler;
	(this.Parent as Border)!.Margin = 0;	
}

What else will break with new update...

SergTomcat avatar Jul 08 '25 14:07 SergTomcat

You can control this through https://github.com/CommunityToolkit/Maui/pull/2759 which should be in the latest release. Styling fixes will come in the next release.

Or you can set the Margin property on your content as the OP suggests

bijington avatar Jul 08 '25 14:07 bijington

Are there any updates on this? I see there's a Pull Request open to address this but it seems like it hasn't had activity in a bit. The default settings don't have a good way to do Light/Dark theme binding for the background color which is the main issue for me.

srclark213 avatar Jul 28 '25 15:07 srclark213