Maui
Maui copied to clipboard
[BUG] Padding and Margin are not applied to the Popup class of Popup2 by Style attribute
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
- Create a Style to be applied to the Popup and set Padding and Margin.
- 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>
- 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>
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
I can also reproduce it.
Same here
This is also the case with BackgroundColor, HorizontalOptions, VerticalOptions, BackgroundColor.
HeightRequest and WidthRequest seem to work.
Absolutely true. There is some unnesessary Border that appears, that, in theory, should catch all properties from popup, but it doesn't.
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...
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
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.