ContentButton
is just a button that can hold whatever content you want. In order to use this control, you need to call the UseSimpleToolkit()
extension method in your MauiProgram.cs
file:
builder.UseSimpleToolkit();
ContentButton
can be found in the following XAML namespace:
xmlns:simpleCore="clr-namespace:SimpleToolkit.Core;assembly=SimpleToolkit.Core"
Let's define a ContentButton
with an Icon
and Label
:
<simpleCore:ContentButton
Clicked="StarButtonClicked"
Background="Orange"
HorizontalOptions="Center"
StrokeShape="{RoundRectangle CornerRadius=6}">
<HorizontalStackLayout Padding="12,10" Spacing="10">
<simpleCore:Icon
Source="star.png" TintColor="White"
VerticalOptions="Center"
HeightRequest="18" WidthRequest="18"/>
<Label
Text="Star this repo" TextColor="White"
FontAttributes="Bold"
VerticalOptions="Center"/>
</HorizontalStackLayout>
</simpleCore:ContentButton>
The button border can be modified the same way as the Border
control. Output:
ContentButton
provides the same visual states as .NET MAUI Button
does:
<simpleCore:ContentButton
Clicked="StarButtonClicked"
Background="Orange"
HorizontalOptions="Center"
StrokeShape="{RoundRectangle CornerRadius=6}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup>
<VisualState x:Name="Normal"/>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter
Property="Background"
Value="OrangeRed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter
Property="Background"
Value="DarkOrange"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
<HorizontalStackLayout Padding="12,10" Spacing="10">
<simpleCore:Icon
Source="star.png" TintColor="White"
VerticalOptions="Center"
HeightRequest="18" WidthRequest="18"/>
<Label
Text="Star this repo" TextColor="White"
FontAttributes="Bold"
VerticalOptions="Center"/>
</HorizontalStackLayout>
</simpleCore:ContentButton>
Output:
Since version 5.0.0, the ContentButton
class is inherited from the .NET MAUI Border
control. ContentButton
has these events and properties in addition to Border
s events and properties:
Clicked
- an event that fires when the button is clickedPressed
- an event that fires when the button is pressedReleased
- an event that fires when the button is releasedCommand
- a command that is invoked when the button is clickedCommandParameter
- a parameter to pass to theCommand
property