Getting Started with .NET MAUI Toolbar
This section provides a quick overview of how to get started with the .NET MAUI SfToolbar for .NET MAUI and a walk-through to configure the .NET MAUI Toolbar in a real-time scenario. Follow the steps below to add .NET MAUI Toolbar control to your project.
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 8 SDK or later is installed.
- Set up a .NET MAUI environment with Visual Studio 2022 (v17.3 or later).
Step 1: Create a new .NET MAUI Project
- 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.
Step 2: Install the Syncfusion® MAUI Toolbar NuGet Package
- In Solution Explorer, right-click the project and choose Manage NuGet Packages.
- Search for Syncfusion.Maui.Toolbar and install the latest version.
- Ensure the necessary dependencies are installed correctly, and the project is restored.
Step 3: Register the handler
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;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.ConfigureSyncfusionCore()
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("MauiMaterialAssets.ttf", "MaterialAssets");
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
return builder.Build();
}
}
Step 4: Add a Toolbar
- To initialize the control, import the Toolbar namespace into your code.
- Initialize Toolbar
<ContentPage
. . .
xmlns:toolbar="clr-namespace:Syncfusion.Maui.Toolbar;assembly=Syncfusion.Maui.Toolbar">
<StackLayout>
<toolbar:SfToolbar />
</StackLayout>
</ContentPage>
using Syncfusion.Maui.Toolbar;
namespace ToolbarGettingStarted
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
StackLayout stackLayout = new StackLayout();
SfToolbar toolbar = new SfToolbar();
stackLayout.Children.Add(toolbar);
this.Content = stackLayout;
}
}
}
Prerequisites
Before proceeding, ensure the following are set up:
- Install .NET 8 SDK or later is installed.
- Set up a .NET MAUI environment with Visual Studio Code.
- Ensure that the .NET MAUI extension is installed and configured as described here.
Step 1: Create a new .NET MAUI Project
- 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® MAUI Toolbar NuGet Package
- Press Ctrl + ` (backtick) to open the integrated terminal in Visual Studio Code.
- Ensure you’re in the project root directory where your .csproj file is located.
- Run the command dotnet add package Syncfusion.Maui.Toolbar to install the Syncfusion® .NET MAUI Toolbar package.
- To ensure all dependencies are installed, run
dotnet restore
.
Step 3: Register the handler
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;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.ConfigureSyncfusionCore()
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("MauiMaterialAssets.ttf", "MaterialAssets");
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
return builder.Build();
}
}
Step 4: Add a Toolbar
- To initialize the control, import the Toolbar namespace into your code.
- Initialize Toolbar
<ContentPage
. . .
xmlns:toolbar="clr-namespace:Syncfusion.Maui.Toolbar;assembly=Syncfusion.Maui.Toolbar">
<StackLayout>
<toolbar:SfToolbar />
</StackLayout>
</ContentPage>
using Syncfusion.Maui.Toolbar;
namespace ToolbarGettingStarted
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
StackLayout stackLayout = new StackLayout();
SfToolbar toolbar = new SfToolbar();
stackLayout.Children.Add(toolbar);
this.Content = stackLayout;
}
}
}
Prerequisites
Before proceeding, ensure the following are set up:
- Ensure you have the latest version of JetBrains Rider.
- Install .NET 8 SDK or later is installed.
- Make sure the MAUI workloads are installed and configured as described here.
Step 1: Create a new .NET MAUI Project
- Go to File > New Solution, Select .NET (C#) and choose the .NET MAUI App template.
- Enter the Project Name, Solution Name, and Location.
- Select the .NET framework version and click Create.
Step 2: Install the Syncfusion® MAUI Toolbar NuGet Package
- In Solution Explorer, right-click the project and choose Manage NuGet Packages.
- Search for Syncfusion.Maui.Toolbar and install the latest version.
- Ensure the necessary dependencies are installed correctly, and the project is restored. If not, Open the Terminal in Rider and manually run:
dotnet restore
Step 3: Register the handler
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;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.ConfigureSyncfusionCore()
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("MauiMaterialAssets.ttf", "MaterialAssets");
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
return builder.Build();
}
}
Step 4: Add .NET MAUI Toolbar control
- To initialize the control, import the
Syncfusion.Maui.Toolbar
namespace into your code. - Initialize SfToolbar
<ContentPage
...
xmlns:toolbar="clr-namespace:Syncfusion.Maui.Toolbar;assembly=Syncfusion.Maui.Toolbar">
<StackLayout>
<toolbar:SfToolbar />
</StackLayout>
</ContentPage>
using Syncfusion.Maui.Toolbar;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
StackLayout stackLayout = new StackLayout();
SfToolbar toolbar = new SfToolbar();
stackLayout.Children.Add(toolbar);
this.Content = stackLayout;
}
}
Adding Toolbar items
You can use Items property of SfToolbar to populate the toolbar items.
<ContentPage
...
xmlns:toolbar="clr-namespace:Syncfusion.Maui.Toolbar;assembly=Syncfusion.Maui.Toolbar">
<toolbar:SfToolbar x:Name="Toolbar" HeightRequest="56">
<toolbar:SfToolbar.Items>
<toolbar:SfToolbarItem Name="Bold"
ToolTipText="Bold">
<toolbar:SfToolbarItem.Icon>
<FontImageSource Glyph=""
FontFamily="MauiMaterialAssets" />
</toolbar:SfToolbarItem.Icon>
</toolbar:SfToolbarItem>
<toolbar:SfToolbarItem Name="Underline"
ToolTipText="Underline">
<toolbar:SfToolbarItem.Icon>
<FontImageSource Glyph=""
FontFamily="MauiMaterialAssets" />
</toolbar:SfToolbarItem.Icon>
</toolbar:SfToolbarItem>
<toolbar:SfToolbarItem Name="Italic"
ToolTipText="Italic">
<toolbar:SfToolbarItem.Icon>
<FontImageSource Glyph=""
FontFamily="MauiMaterialAssets" />
</toolbar:SfToolbarItem.Icon>
</toolbar:SfToolbarItem>
<toolbar:SfToolbarItem Name="AlignLeft"
ToolTipText="Align-Left">
<toolbar:SfToolbarItem.Icon>
<FontImageSource Glyph=""
FontFamily="MauiMaterialAssets" />
</toolbar:SfToolbarItem.Icon>
</toolbar:SfToolbarItem>
<toolbar:SfToolbarItem Name="AlignRight"
ToolTipText="Align-Right">
<toolbar:SfToolbarItem.Icon>
<FontImageSource Glyph=""
FontFamily="MauiMaterialAssets" />
</toolbar:SfToolbarItem.Icon>
</toolbar:SfToolbarItem>
<toolbar:SfToolbarItem Name="AlignCenter"
ToolTipText="Align-Center">
<toolbar:SfToolbarItem.Icon>
<FontImageSource Glyph=""
FontFamily="MauiMaterialAssets" />
</toolbar:SfToolbarItem.Icon>
</toolbar:SfToolbarItem>
<toolbar:SfToolbarItem Name="AlignJustify"
ToolTipText="Align-Justify">
<toolbar:SfToolbarItem.Icon>
<FontImageSource Glyph=""
FontFamily="MauiMaterialAssets" />
</toolbar:SfToolbarItem.Icon>
</toolbar:SfToolbarItem>
</toolbar:SfToolbar.Items>
</toolbar:SfToolbar>
</ContentPage>
using Syncfusion.Maui.Toolbar;
namespace ToolbarGettingStarted
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfToolbar toolbar = new SfToolbar();
toolbar.HeightRequest = 56;
ObservableCollection<BaseToolbarItem> itemCollection = new ObservableCollection<BaseToolbarItem>
{
new SfToolbarItem
{
Name = "Bold",
ToolTipText = "Bold",
Icon = new FontImageSource { Glyph = "\uE770", FontFamily = "MauiMaterialAssets" }
},
new SfToolbarItem
{
Name = "Underline",
ToolTipText = "Underline",
Icon = new FontImageSource { Glyph = "\uE762", FontFamily = "MauiMaterialAssets" }
},
new SfToolbarItem
{
Name = "Italic",
ToolTipText = "Italic",
Icon = new FontImageSource { Glyph = "\uE771", FontFamily = "MauiMaterialAssets" }
},
new SfToolbarItem
{
Name = "AlignLeft",
ToolTipText = "Align-Left",
Icon = new FontImageSource { Glyph = "\uE751", FontFamily = "MauiMaterialAssets" }
},
new SfToolbarItem
{
Name = "AlignRight",
ToolTipText = "Align-Right",
Icon = new FontImageSource { Glyph = "\uE753", FontFamily = "MauiMaterialAssets" }
},
new SfToolbarItem
{
Name = "AlignCenter",
ToolTipText = "Align-Center",
Icon = new FontImageSource { Glyph = "\uE752", FontFamily = "MauiMaterialAssets" }
},
new SfToolbarItem
{
Name = "AlignJustify",
ToolTipText = "Align-Justify",
Icon = new FontImageSource { Glyph = "\uE74F", FontFamily = "MauiMaterialAssets" }
}
};
toolbar.Items = itemCollection;
this.Content = toolbar;
}
}
}
Note: Please refer to the link to add the
MauiMaterialAssets
custom font.
You can find the getting started sample of .NET MAUI SfToolbar from this GettingStarted.