Syncfusion® Toolkit for .NET MAUI

repository·main·Indexed 20 days ago

https://github.com/syncfusion/maui-toolkit

A high-performance collection of UI controls for cross-platform app development on Android, iOS, macOS, and Windows. The toolkit includes controls for data visualization (Cartesian, Circular, and Spark charts), calendars, editors, navigation, layout, buttons, and notifications. It provides the Syncfusion.Maui.Toolkit NuGet package and requires configuration via the .ConfigureSyncfusionToolkit() extension method in MauiProgram.cs.

Tokens
2.7K
Snippets
7
Records
12
Agent score
23%

What's inside Syncfusion MAUI Toolkit

  1. Use Syncfusion® Toolkit controls in XAML

    main

    To access the toolkit's controls within your XAML files, declare the toolkit namespace using the following URI:

    xmlns:toolkit="http://schemas.syncfusion.com/maui/toolkit"

    xmlns:toolkit="http://schemas.syncfusion.com/maui/toolkit"
  2. Install the Syncfusion® Toolkit for .NET MAUI

    main

    You can install the toolkit using the .NET CLI or by manually adding the package reference to your project file.

    Using .NET CLI:

    dotnet add package Syncfusion.Maui.Toolkit

    Using .csproj file: Add the following line to your project file:

    <PackageReference Include="Syncfusion.Maui.Toolkit" Version="x.x.x" />
  3. Configure the Syncfusion® Toolkit in MauiProgram.cs

    main

    To enable the toolkit in your application, you must call the .ConfigureSyncfusionToolkit() extension method during the app builder initialization in your MauiProgram.cs file. This requires the Syncfusion.Maui.Toolkit.Hosting namespace.

    using Syncfusion.Maui.Toolkit.Hosting;
    
    public static class MauiProgram
    {
    	public static MauiApp CreateMauiApp()
    	{
    		var builder = MauiApp.CreateBuilder();
    		builder
    		.UseMauiApp<App>()
    		// Initialize the Syncfusion .NET MAUI Toolkit
    		.ConfigureSyncfusionToolkit()
    		.ConfigureFonts(fonts =>
    		{
    			fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
    			fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
    		});
    
    		return builder.Build();
    	}
    }
  4. Initial Setup for Windows

    main

    To develop with the Syncfusion Toolkit for .NET MAUI on Windows, ensure the following prerequisites are met:

    1. Visual Studio: Install Visual Studio 17.10 or newer and ensure the .NET MAUI workload is included.
    2. iOS Development (Optional): If using 'Pair to Mac', install the latest stable version of Xcode on your Mac.
    3. Android SDKs: Ensure necessary Android SDKs are installed via the Android SDK Manager or through Visual Studio prompts.
    4. Java: Install OpenJDK 17.
  5. Build the Build Tasks

    main

    Before opening the solution in an IDE, you must build the build tasks from the command line. Navigate to your cloned repository root and execute the following commands:

    1. Restore dotnet tools.
    2. Build the solution file.
    cd \repos\maui-toolkit
    dotnet tool restore
    dotnet build ./Syncfusion.Maui.Toolkit.sln
  6. Create a data model and ViewModel for SfCartesianChart

    main

    When using Syncfusion charts, you must provide a data model and a ViewModel to facilitate data binding.

    1. Data Model: Create a class (e.g., Person) with properties that correspond to the XBindingPath and YBindingPath used in your XAML series.
    2. ViewModel: Create a class containing a collection (e.g., List<T>) that holds instances of your data model. This collection should be exposed via a public property (e.g., Data) so it can be bound to the chart's ItemsSource.
    // Person.cs
    public class Person
    {
        public string Name { get; set; }
        public double Height { get; set; }
    }
    
    // ViewModel.cs
    public class ViewModel
    {
        public List<Person> Data { get; set; }
    
        public ViewModel()
        {
            Data = new List<Person>()
            {
                new Person { Name = "David", Height = 170 },
                new Person { Name = "Michael", Height = 96 },
                new Person { Name = "Steve", Height = 65 },
                new Person { Name = "Joel", Height = 182 },
                new Person { Name = "Bob", Height = 134 }
            };
        }
    }
  7. Implement a basic SfCartesianChart

    main

    To visualize data using a Cartesian Chart, you need to set up a SfCartesianChart in XAML, define its axes, and bind a data series to a collection in your ViewModel.

    Key Steps:

    1. Namespace Declaration: Add xmlns:chart="clr-namespace:Syncfusion.Maui.Toolkit.Charts;assembly=Syncfusion.Maui.Toolkit" to your XAML file.
    2. Axes Configuration: Use CategoryAxis for categorical data (e.g., names on the X-axis) and NumericalAxis for continuous data (e.g., values on the Y-axis).
    3. Data Series: Use ColumnSeries (or other series types) and bind the ItemsSource to your data collection. Specify XBindingPath and YBindingPath to map your model properties to the chart axes.
    4. Data Labels: Customize label appearance using DataLabelSettings and CartesianDataLabelSettings.
    <ContentPage 
        xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        x:Class="ChartGettingStarted.MainPage"
        xmlns:chart="clr-namespace:Syncfusion.Maui.Toolkit.Charts;assembly=Syncfusion.Maui.Toolkit"
        xmlns:model="clr-namespace:ChartGettingStarted">
        
        <ContentPage.BindingContext>
            <model:ViewModel/>
        </ContentPage.BindingContext>
    
        <chart:SfCartesianChart>
            <chart:SfCartesianChart.Title>
                <Label Text="Height Comparison" HorizontalOptions="Center" />
            </chart:SfCartesianChart.Title>
    
            <chart:SfCartesianChart.Legend>
                <chart:ChartLegend />
            </chart:SfCartesianChart.Legend>
    
            <chart:SfCartesianChart.XAxes>
                <chart:CategoryAxis>
                    <chart:CategoryAxis.Title>
                        <chart:ChartAxisTitle Text="Name" />
                    </chart:CategoryAxis.Title>
                </chart:CategoryAxis>
            </chart:SfCartesianChart.XAxes>
    
            <chart:SfCartesianChart.YAxes>
                <chart:NumericalAxis>
                    <chart:NumericalAxis.Title>
                        <chart:ChartAxisTitle Text="Height(in cm)" />
                    </chart:NumericalAxis.Title>
                </chart:NumericalAxis>
            </chart:SfCartesianChart.YAxes>
    
            <chart:ColumnSeries Label="Height"
                             EnableTooltip="True" 
                             ShowDataLabels="True" 
                             ItemsSource="{Binding Data}" 
                             XBindingPath="Name" 
                             YBindingPath="Height">
                <chart:ColumnSeries.DataLabelSettings>
                    <chart:CartesianDataLabelSettings LabelPlacement="Inner" />
                </chart:ColumnSeries.DataLabelSettings>
            </chart:ColumnSeries>
        </chart:SfCartesianChart>
    </ContentPage>
  8. Syncfusion® Toolkit Controls Reference

    main

    The toolkit provides a wide range of high-performance UI controls categorized by functionality:

    CategoryControls
    Data VisualizationCartesian Charts, Circular Charts, Funnel Charts, Polar Charts, Pyramid Charts, Spark Charts, Sunburst Charts
    CalendarsCalendar
    EditorsDate Picker, Date Time Picker, Numeric Entry, Numeric Up Down, OTP Input, Picker, Time Picker
    NavigationBottom Sheet, Navigation Drawer, Tab View
    LayoutAccordion, Cards, Carousel, Expander, Popup, Text Input Layout
    ButtonsButton, Chips, Segmented Control
    NotificationCircular Progress Bar, Linear Progress Bar, Pull to Refresh
    MiscellaneousEffects View, Shimmer
  9. Explore Sample Projects

    main

    The repository includes sample projects located in the samples directory for testing and demonstration:

    • Syncfusion.Maui.ControlsGallery: A comprehensive gallery showcasing all toolkit controls and features.
    • Syncfusion.Maui.Controls.Samples.Sandbox: An empty project designed for testing specific use cases or reproducing issues.
    ├── samples 
    │   ├── Syncfusion.Maui.ControlsGallery
    │   ├── Syncfusion.Maui.Controls.Samples.Sandbox