Getting started with .NET MAUI Card
26 Sep 20249 minutes to read
This section details the process of integrating the .NET MAUI Cards control and focuses solely on the fundamental features required for initiating your exploration of Syncfusion Card. Follow the steps below to add a .NET MAUI Cards control to your project.
To get start quickly with our .NET MAUI Cards, you can check the below video.
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 7 SDK or later is installed.
- Set up a .NET MAUI environment with Visual Studio 2022 (v17.3 or later) or Visual Studio Code. For Visual Studio Code users, ensure that the .NET MAUI workload is installed and configured as described here.
Step 1: Create a New .NET MAUI Project
Visual Studio
- Go to File > New > Project and choose the .NET MAUI App template.
- Name the project and choose a location. Then click Next.
- Select the .NET framework version and click Create.
Visual Studio Code
- Open the command palette by pressing
Ctrl+Shift+P
and type .NET:New Project and enter. - Choose the .NET MAUI App template.
- Select the project location, type the project name and press Enter.
- Then choose Create project.
Step 2: Install the Syncfusion .NET MAUI Cards NuGet Package
- In Solution Explorer, right-click the project and choose Manage NuGet Packages.
- Search for Syncfusion.Maui.Cards and install the latest version.
- Ensure the necessary dependencies are installed correctly, and the project is restored.
Step 3: Register the handler
The Syncfusion.Maui.Core NuGet is a dependent package for all Syncfusion controls of .NET MAUI. In the MauiProgram.cs file, register the handler for Syncfusion core.
using Syncfusion.Maui.Core.Hosting;
namespace GettingStarted
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.ConfigureSyncfusionCore();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
return builder.Build();
}
}
}
Step 4: Add .NET MAUI Cards control
- To initialize the control, import the
Syncfusion.Maui.Cards
namespace into your code. - Initialize SfCards.
<ContentPage
. . .
xmlns:cards="clr-namespace:Syncfusion.Maui.Cards;assembly=Syncfusion.Maui.Cards">
<cards:SfCardView>
<Label Text="CardView" Background="PeachPuff" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</cards:SfCardView>
</ContentPage>
using Syncfusion.Maui.Cards;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfCardView cardView = new SfCardView();
cardView.Content = new Label()
{
Text = "CardView",
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
BackgroundColor = Colors.PeachPuff
};
this.Content = cardView;
}
}
SwipeToDismiss
The SwipeToDismiss property enables or disables the swiping feature in SfCardView.
<cards:SfCardView SwipeToDismiss="true">
<Label Text="SfCardView" Background="MediumPurple" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</cards:SfCardView>
using Syncfusion.Maui.Cards;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfCardView cardView = new SfCardView();
cardView.SwipeToDismiss = true;
cardView.Content = new Label()
{
Text="SfCardView",
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
BackgroundColor = Colors.MediumPurple
};
this.Content = cardView;
}
}
NOTE
This property will not work when adding the SfCardView as a child of SfCardLayout.
Dismiss the card programmatically
The IsDismissed property enables you to retrieve the view state of the card, and also provides the capability for the user to programmatically modify the card’s view state.
<card:SfCardView IsDismissed="true">
<Label Text="SfCardView"/>
</card:SfCardView>
using Syncfusion.Maui.Cards;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfCardView cardView = new SfCardView();
cardView.IsDismissed = true;
cardView.Content = new Label(){ Text="SfCardView" };
this.Content = cardView;
}
}
SfCardLayout
Initialize a card layout with a card view using the provided code sample below.
<cards:SfCardLayout HeightRequest="500" BackgroundColor="#F0F0F0">
<cards:SfCardView CornerRadius="10">
<Label Text="Peach" BackgroundColor="PeachPuff" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
</cards:SfCardView>
<cards:SfCardView CornerRadius="10">
<Label Text="MediumPurple" BackgroundColor="MediumPurple" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
</cards:SfCardView>
<cards:SfCardView CornerRadius="10" >
<Label Text="LightPink" BackgroundColor="LightPink" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
</cards:SfCardView>
</cards:SfCardLayout>
using Syncfusion.Maui.Cards;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfCardLayout cardLayout = new SfCardLayout();
//Add children for card layout
cardLayout.Children.Add(new SfCardView() { Content = new Label() { Text = "Peach", BackgroundColor = Colors.PeachPuff, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }, CornerRadius = 15 });
cardLayout.Children.Add(new SfCardView() { Content = new Label() { Text = "MediumPurple", BackgroundColor = Colors.MediumPurple, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center },CornerRadius = 15 });
cardLayout.Children.Add(new SfCardView() { Content = new Label() { Text = "LightPink", BackgroundColor = Colors.LightPink, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center },CornerRadius = 15 });
this.Content = cardLayout;
}
}
NOTE
You can refer to our .NET MAUI Cards feature tour page for its groundbreaking feature representations. You can also explore our .NET MAUI Cards Example that shows you how to render and configure the Cards in .NET MAUI.