| layout | post |
|---|---|
| title | Getting Started with WPF AI AssistView control | Syncfusion |
| description | Learn about getting started with the Syncfusion WPF AI AssistView (SfAIAssistView) control with its basic features. |
| platform | wpf |
| control | AI AssistView |
| documentation | ug |
This section explains the steps required to add the Wpf SfAIAssistView control with its basic features.
- Create a Wpf desktop app for C# and .NET 6.
- Add reference to Syncfusion.SfChat.Wpf NuGet.
- Import the control namespace
Syncfusion.UI.Xaml.Chatin XAML or C# code. - Initialize the SfAIAssistView control.
{% tabs %} {% highlight xaml %}
<syncfusion:SfAIAssistView />
{% endhighlight %} {% endtabs %}
- Create a Wpf desktop app for C# and .NET 6.
- Add reference to Syncfusion.SfChat.Wpf NuGet.
- Import the control namespace
Syncfusion.UI.Xaml.Chatin XAML or C# code. - Initialize the SfAIAssistView control.
{% tabs %} {% highlight C# %}
using Syncfusion.UI.Xaml.Chat;
namespace GettingStarted { ///
{% endhighlight %} {% endtabs %}
Create a simple chat collection as shown in the following code example in a new class file. Save it as ViewModel.cs file.
{% tabs %} {% highlight C# %}
public class ViewModel : INotifyPropertyChanged
{
private ObservableCollection chats;
private Author currentUser;
public ViewModel()
{
this.Chats = new ObservableCollection();
this.CurrentUser = new Author { Name="John"};
this.GenerateMessages();
}
private async void GenerateMessages()
{
this.Chats.Add( new TextMessage { Author = CurrentUser, Text = "What is WPF?" } );
await Task.Delay(1000);
this.Chats.Add( new TextMessage { Author = new Author { Name = "Bot" }, Text = "WPF is a user interface layer that contains modern controls and styles for building Windows apps." });
}
public ObservableCollection<object> Chats
{
get
{
return this.chats;
}
set
{
this.chats = value;
RaisePropertyChanged("Messages");
}
}
public Author CurrentUser
{
get
{
return this.currentUser;
}
set
{
this.currentUser = value;
RaisePropertyChanged("CurrentUser");
}
}
public void RaisePropertyChanged(string propName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
{% endhighlight %} {% endtabs %}
Set the ViewModel as the DataContext for the AI AssistView or the parent window. This allows data binding between the UI and the ViewModel properties. To populate AI AssistView, bind the chats in ViewModel to Messages property of AI AssistView.
{% tabs %} {% highlight xaml %}
<Grid.DataContext>
local:ViewModel/
</Grid.DataContext>
<syncfusion:SfAIAssistView CurrentUser="{Binding CurrentUser}"
Messages="{Binding Chats}"/>
{% endhighlight %} {% endtabs %}

