Getting Started with .NET MAUI AI AssistView

8 Jul 20268 minutes to read

This section guides you through setting up and configuring AI AssistView (SfAIAssistView) in your .NET MAUI application. Follow the steps below to add a basic AI AssistView to your project.

To quickly get started with the .NET MAUI AI AssistView, watch this video:

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with Visual Studio 2022 v17.12 or later.

Step 1: Create a new .NET MAUI project

  1. Go to File > New > Project and choose the .NET MAUI App template.
  2. Name the project and choose a location. Then, click Next.
  3. Select the .NET framework version and click Create.

Step 2: Install the Syncfusion® MAUI AI AssistView NuGet package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.AIAssistView and install the latest version.
  3. Ensure the necessary dependencies are installed correctly, and the project is restored.

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with Visual Studio Code.
  3. Ensure that the .NET MAUI workloads are installed and configured as described here.

Step 1: Create a new .NET MAUI project

  1. Open the command palette by pressing Ctrl+Shift+P and type .NET:New Project and enter.
  2. Choose the .NET MAUI App template.
  3. Select the project location, type the project name and press Enter.
  4. Then choose Create project.

Step 2: Install the Syncfusion® MAUI AI AssistView NuGet package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.AIAssistView and install the latest version.
  3. Ensure the necessary dependencies are installed correctly, and the project is restored.

Prerequisites

Before proceeding, ensure the following are set up:

  1. Install .NET 9 SDK or later.
  2. Set up a .NET MAUI environment with JetBrains Rider 2024.3 or later.
  3. Make sure the MAUI workloads are installed and configured as described here.

Step 1: Create a new .NET MAUI project

  1. Go to File > New Solution. Select .NET (C#) and choose the .NET MAUI App template.
  2. Enter the Project Name, Solution Name, and Location.
  3. Select the .NET framework version and click Create.

Step 2: Install the Syncfusion® MAUI AI AssistView NuGet package

  1. In Solution Explorer, right-click the project and choose Manage NuGet Packages.
  2. Search for Syncfusion.Maui.AIAssistView and install the latest version.
  3. 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 Syncfusion handler

Add the required namespace

using Syncfusion.Maui.Core.Hosting;

Register the Syncfusion handler

Register the Syncfusion core handler in your CreateMauiApp method of MauiProgram.cs file.

builder.ConfigureSyncfusionCore();

Step 4: Define the view model

Next, create a view model class and initialize the collection of AssistItem instances as follows.

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Threading.Tasks;
using Syncfusion.Maui.AIAssistView;

public class GettingStartedViewModel : INotifyPropertyChanged
{
    private ObservableCollection<IAssistItem> assistItems;

    public GettingStartedViewModel()
    {
        this.assistItems = new ObservableCollection<IAssistItem>();
        this.GenerateAssistItems();
    }

    public ObservableCollection<IAssistItem> AssistItems
    {
        get{return this.assistItems;}
        set
        {
            if (assistItems != value)
            {
                assistItems = value;
                RaisePropertyChanged(nameof(AssistItems));
            }
        }
    }

    private async void GenerateAssistItems()
    {
        AssistItem requestItem = new AssistItem()
        {
            Text = "listening",
            IsRequested = true
        };

        this.AssistItems.Add(requestItem);
        await GetResult(requestItem);
    }

    private async Task GetResult(AssistItem requestItem)
    {
        await Task.Delay(1000).ConfigureAwait(true);

        AssistItem responseItem = new AssistItem()
        {
            Text = "Types of Listening : For a good communication, it is not only enough to convey the information efficiently, but it also needs to include good listening skill. Common types of Listening are Active listening and Passive listening.",
            IsRequested = false,
        };
        this.AssistItems.Add(responseItem);
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(string propName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }
}

NOTE

The SfAIAssistView.AssistItems property is of type IList<IAssistItem>. To ensure the AssistItems property functions correctly, it is recommended to use a collection property in the ViewModel with the same type, such as ObservableCollection<IAssistItem>.

Step 5: Import the AI AssistView namespace

Add the following namespace in your XAML or C#.

xmlns:syncfusion="clr-namespace:Syncfusion.Maui.AIAssistView;assembly=Syncfusion.Maui.AIAssistView"
using Syncfusion.Maui.AIAssistView;

Step 6: Add the AI AssistView component

Set the ViewModel as the BindingContext for the AI AssistView or the parent ContentPage. This allows data binding between the UI and the ViewModel properties.
Create an instance of the SfAIAssistView control. To populate AI AssistView, bind the assist items in ViewModel to AssistItems property of AI AssistView.

<ContentPage.BindingContext>
    <local:GettingStartedViewModel />
</ContentPage.BindingContext>

<syncfusion:SfAIAssistView x:Name="sfAIAssistView"
                           AssistItems="{Binding AssistItems}" />
using Syncfusion.Maui.AIAssistView;

public partial class MainPage : ContentPage
{
    private SfAIAssistView aiAssistView;

    public MainPage()
    {
        InitializeComponent();
        this.aiAssistView = new SfAIAssistView();
        GettingStartedViewModel viewModel = new GettingStartedViewModel();
        this.aiAssistView.AssistItems = viewModel.AssistItems;
        this.Content = this.aiAssistView;
    }
}

The following screenshot illustrates the result of the above code.

Syncfusion .NET MAUI AI AssistView control

You can download the AI AssistView Getting Started sample from GitHub