Repository navigation
Description
Description
This is an API design oversight, I believe. The Border component has properties, such as Stroke, StrokeThickness, Fill etc. The border shape is specified via the StrokeShape property of type IShape. The implementing Shape class also has properties, such as Stroke, StrokeThickness, Fill etc. This is really confusing, because it is not known which set of properties is respected.
In my humble opinion, the correct type of the stroke shape should be Geometry, similar to what we use for the Clip property. In fact, it would be nice to clip the inner contents of the Border to that Geometry. For consistency, the property should be renamed to StrokeGeometry as well.
In addition to this, I believe it is not very convenient to require specifying the border shape always, to see any border on the screen. If the border shape is not specified, it should default to a rectangular border, as this is the most common use case.
API Changes
- Remove or make obsolete the
StrokeShapeproperty of theBorderclass. - Add a new property
StrokeGeometryof typeGeometryto theBorderclass. - Make the
StrokeGeometryoptional, defaulting to aRectangleGeometry, if not specified.
Usage Scenarios
var border = new Border
{
Stroke = new SolidColorBrush(Colors.Red),
StrokeGeometry = new RectangleGeometry(),
StrokeThickness = 5
};<Border Stroke="Red" StrokeThickness="5">
<Border.StrokeGeometry>
<RectangleGeometry />
</Border.StrokeGeometry>
</Border>Backward Compatibility
If the original StrokeShape property is made obsolete, then the backward compatibility can be maintained. I vote for introducing a breaking change by removing the StrokeShape property and replacing it with the new StrokeGeometry property, however. Having a brand new framework with some legacy APIs from day one is not very good in my books.
Difficulty
Medium
Activity
[-]Border StrokeShape should be Geometry, not a Shape[/-][+]Border StrokeShape should be a Geometry, not a Shape[/+]vanka78bg commentedon Nov 26, 2021
After investigating the matter some more, I have discovered that both
ShapeandGeometryclasses implement theIShapeinterface. Setting theStrokeShapeproperty to an instance derived fromShaperenders the border correctly, while setting it to an instance derived fromGeometrydoes not render any border at all. Now, I do not know whether this is a bug, or just the API is letting me to assign values of unsupported types. Anyway, I am more convinced this API needs some serious rethinking.I would suggest having two interfaces:
IGeometryandIShape, as these interfaces are intended to be consumed by theHandlers. TheIShapeinterface can inherit formIGeometry. Now it would be possible to expose all theseStroke,StrokeThickness,Filletc. properties from theIShapeinterface. This way theHandlers would not have to castIShapetoShapeevery time to get access to them.vanka78bg commentedon Nov 26, 2021
Another thing to note: currently it is not possible to set a rectangular shape in XAML. For instance, the following XAML code snippet would not work:
There is a naming conflict between
Microsoft.Maui.Graphics.RectangleandMicrosoft.Maui.Controls.Shapes.Rectangle. Apparently, the XAML parser cannot determine which type to use, so it tries to set the wrong one. This is rather inconvenient, becauseRectangleis the most common border type. Using aGeometrywould allows us to specify it like this:shimingsg commentedon Mar 18, 2022
verified with VS 17.2.0 Preview 3.0 [32317.292.main], the Rectangle is just in Microsoft.Maui.Controls.Shapes
the following XAML code snippet works fine but RectangleGeometry was not found in Border
demo: MauiApp3558.zip
whichone commentedon Jul 3, 2022
It seems that only Ellipse, Recangle, RoundRectangle can be resized properly based on the content inside. Other shapes like line, path, polyline etc, are drawn with fixed dimensions and won't be resized to hold the content as a BORDER. What's the scenario to use them then?
Ghasan commentedon Jul 11, 2022
I don't think it needs to be a Geometry, but I understand the confusion, which needs to be fixed. Maybe into making Rectangle, RectangeShape, and RectangeGeometry?
It needs to stay as IShape so that we don't need to define size for border shape, we don't really care about the geometry of the border, but rather the outer shape, size is managed by HeightRequest and WidthRequest etc.
2 remaining items
jinxinjuan commentedon Apr 14, 2023
Verified with VS 17.6.0 Preview 3.0, The StrokeShape is Geometry, but property StrokeGeometry is not found in Border.

mattleibow commentedon Nov 3, 2023
@PureWeen @drasticactions Related to offline discussions.
mattleibow commentedon Nov 3, 2023
Related to #16919
dalux-tke commentedon Jan 28, 2026
This issue was linked to here and closed. However, I am still having the issue in the closed ticket as the live preview crashes due to that error.
Is there any news on the state of this old issue?