-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
If you nest two Border objects so one contains the other, the bounds are not set appropriately to match the requested sizes based on padding. 1 erroneous pixel is added in every direction by the nesting (in all of Windows/iOS/Android).
In the demo code below, in all operating systems (iOS/Windows/Android), where an outer Border is set to 10 pixels padding, the bounds of the outer Border (height or width) minus the inner Border will result in 22 pixels (an extra two pixels - should be 20 pixels, ie. 2x padding).
This is preventing correct anticipation of sizes of objects for manual layouts.
Steps to Reproduce
-
Create a blank MAUI project in Visual Studio 2022 with .NET 7.0 by File > New named "Border Bounds Bug"
-
Copy and paste the following code into App.xaml.cs to replace the entire file:
using Microsoft.Maui.Controls.Shapes;
using System.Diagnostics;
namespace Border_Bounds_Bug {
public partial class App : Application {
public App() {
InitializeComponent();
MainPage = new ContentPage();
VerticalStackLayout vert = new();
(MainPage as ContentPage).Content = vert;
Border border = new();
border.StyleId = "OUTER BORDER";
border.BackgroundColor = Colors.DarkBlue;
border.Padding = new Thickness(10);
border.Margin = 0;
border.StrokeShape = new RoundRectangle { CornerRadius = new CornerRadius(30), StrokeThickness = 0 };
vert.Children.Add(border);
Border innerBorder = new();
innerBorder.StyleId = "INNER BORDER";
innerBorder.HeightRequest = 60;
innerBorder.BackgroundColor = Colors.White;
//innerBorder.StrokeShape = new RoundRectangle { CornerRadius = new CornerRadius(20), StrokeThickness = 0 };
innerBorder.Padding = 0;
innerBorder.Margin = 0;
border.Content = innerBorder;
//==================================
//CLICK TEST BEHAVIOR
//==================================
TapGestureRecognizer gesture = new();
border.GestureRecognizers.Add(gesture);
gesture.Tapped += delegate {
Debug.WriteLine("BORDER WIDTH " + border.Bounds.Width + " INNER BORDER WIDTH " + innerBorder.Bounds.Width + " | DIFFERENCE " + (border.Bounds.Width - innerBorder.Bounds.Width));
Debug.WriteLine("BORDER HEIGHT " + border.Bounds.Height + " INNER BORDER HEIGHT " + innerBorder.Bounds.Height + " | DIFFERENCE " + (border.Bounds.Height - innerBorder.Bounds.Height));
};
}
}
}
- Click on Border on screen to Debug the bounds, which should be a 20 pixel difference from the outer border minus the inner border (due to padding 10 on outer Border) but instead returns a 22 pixel difference on all platforms (iOS/Android/Windows).
Link to public reproduction project repository
See above
Version with bug
7.0.92
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows
Affected platform versions
iOS 16.7, Android, Windows 10
Did you find any workaround?
None.
Relevant log output
No response