Hello,
It is recommended to use Border
to customize controls for corner or shape.
For instance, you could setting the default Border
style in Style.xaml
as the following:
<Style TargetType="Border">
<Setter Property="Stroke" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray500}}" />
<Setter Property="StrokeShape" Value="RoundRectangle 10,10,10,10"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
Then, you could use Border in your pages as:
<Border >
<Entry/>
</Border>
You could refer to Border to get more details.
Update:
You could also use handler to setting corners, please refer to the following code:
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(IView.Background), (handler, view) =>
{
if (view is Entry)
{
#if ANDROID
float[] outerRadii = { 20, 20, 20, 20, 20, 20, 20, 20 };
RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null);
var shape = new Android.Graphics.Drawables.ShapeDrawable(roundRectShape);
shape.Paint.Color = Android.Graphics.Color.Black;
shape.Paint.StrokeWidth = 5;
shape.Paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
handler.PlatformView.SetBackground(shape);
handler.PlatformView.SetPadding(30, 30, 30, 30);
#elif IOS || MACCATALYST
...
#elif WINDOWS
...
#endif
}
});
Update:
SetBackground
and SetBackgroundColor
can not work together, therefore, you need to use shape.Paint.SetStyle(Android.Graphics.Paint.Style.Fill);
or shape.Paint.SetStyle(Android.Graphics.Paint.Style.FillAndStroke);
to fill the background color.
Important: You need to use nameof(IView.Background),
as your handle event name.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.