How to Create a Different Shape of .NET MAUI Button?
This section illustrates how to create various shapes of .NET MAUI Button. In .NET MAUI, you can customize the shape of a button using the CornerRadius property to create various shapes. The CornerRadius
property defines the radius of each corner of the button. This guide provides examples of how to create various shapes for .NET MAUI buttons.
Define Button Style in your XAML Resources:
<ContentPage.Resources>
<Style TargetType="buttons:SfButton" x:Key="sfButtonStyle">
<Setter Property="HeightRequest" Value="50"/>
<Setter Property="WidthRequest" Value="95"/>
<Setter Property="Text" Value="Button"/>
<Setter Property="Margin" Value="8,12,8,0"/>
</Style>
</ContentPage.Resources>
Use a FlexLayout to arrange and display your custom-shaped buttons:
<FlexLayout HorizontalOptions="Start" VerticalOptions="Center"
Direction="Row" Wrap="Wrap" Margin="8"
JustifyContent="Start" AlignContent="Start" AlignItems="Start">
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,0,0,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="0,20,20,0"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="0"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="0,20,0,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,0,20,0"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,0,0,0"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="0,20,0,0"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="0,0,20,0"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="0,0,0,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="0,0,20,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,20,0,0"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,40,40,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="40,20,20,40"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="40,20,40,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,40,20,40"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,40,40,40"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="40,20,40,40"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="40,40,20,40"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="40,40,40,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="40,40,20,20"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="20,20,40,40"/>
<buttons:SfButton Style="{StaticResource sfButtonStyle}" CornerRadius="30,20,40,5"/>
</FlexLayout>
Output
Conclusion
I hope you enjoyed learning how to create different shapes of .NET MAUI Buttons.
You can refer to our .NET MAUI Button feature tour page to learn about its other groundbreaking features. You can explore our .NET MAUI Button documentation to understand how to present and manipulate data.
Check out our .NET MAUI components from the License and downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Button and other .NET MAUI components.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct - Trac, or feedback portal. We are always happy to assist you!