Loading...
Loading...
Guide for implementing Syncfusion Windows Forms AI AssistView (SfAIAssistView) for building conversational AI interfaces in desktop applications. Use this when creating chat interfaces, AI assistants, or chatbots with Windows Forms. Supports OpenAI and Azure OpenAI integration, typing indicators, chat suggestions, message bubbles, and custom views for interactive messaging experiences.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-ai-assistviewusing Syncfusion.WinForms.AIAssistView;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace AIAssistViewDemo
{
public partial class Form1 : Form
{
ViewModel viewModel;
public Form1()
{
InitializeComponent();
viewModel = new ViewModel();
// Create AI AssistView
SfAIAssistView sfAIAssistView1 = new SfAIAssistView();
sfAIAssistView1.Dock = DockStyle.Fill;
this.Controls.Add(sfAIAssistView1);
// Bind messages
sfAIAssistView1.DataBindings.Add("Messages", viewModel, "Chats",
true, DataSourceUpdateMode.OnPropertyChanged);
}
}
// ViewModel
public class ViewModel : INotifyPropertyChanged
{
private ObservableCollection<object> chats;
private Author currentUser;
public ViewModel()
{
this.Chats = new ObservableCollection<object>();
this.CurrentUser = new Author { Name = "John" };
this.GenerateMessages();
}
private async void GenerateMessages()
{
// User message
this.Chats.Add(new TextMessage
{
Author = CurrentUser,
Text = "What is Windows Forms?"
});
await Task.Delay(1000);
// Bot response
this.Chats.Add(new TextMessage
{
Author = new Author { Name = "Bot" },
Text = "Windows Forms is a GUI framework for building Windows desktop applications."
});
}
public ObservableCollection<object> Chats
{
get => this.chats;
set
{
this.chats = value;
RaisePropertyChanged("Chats");
}
}
public Author CurrentUser
{
get => this.currentUser;
set
{
this.currentUser = value;
RaisePropertyChanged("CurrentUser");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
}
}// In ViewModel
private IEnumerable<string> suggestion;
public IEnumerable<string> Suggestion
{
get => this.suggestion;
set
{
this.suggestion = value;
RaisePropertyChanged("Suggestion");
}
}
// Set suggestions after bot response
Suggestion = new ObservableCollection<string>
{
"Tell me more",
"What are alternatives?"
};
// In Form
sfAIAssistView1.DataBindings.Add("Suggestions", viewModel, "Suggestion",
true, DataSourceUpdateMode.OnPropertyChanged);// In ViewModel
private bool showTypingIndicator;
public bool ShowTypingIndicator
{
get => this.showTypingIndicator;
set
{
this.showTypingIndicator = value;
RaisePropertyChanged("ShowTypingIndicator");
}
}
// Usage
ShowTypingIndicator = true;
var response = await GetAIResponse(userMessage);
Chats.Add(new TextMessage { Author = botAuthor, Text = response });
ShowTypingIndicator = false;
// In Form
sfAIAssistView1.DataBindings.Add("ShowTypingIndicator", viewModel,
"ShowTypingIndicator", true, DataSourceUpdateMode.OnPropertyChanged);
sfAIAssistView1.TypingIndicator.Author = new Author
{
Name = "Bot",
AvatarImage = Image.FromFile(@"Assets\bot.png")
};
sfAIAssistView1.TypingIndicator.DisplayText = "Typing";BannerStyle customStyle = new BannerStyle
{
TitleFont = new Font("Segoe UI", 14F, FontStyle.Bold),
SubTitleFont = new Font("Segoe UI", 12F, FontStyle.Italic),
ImageSize = AvatarSize.Medium,
SubTitleColor = Color.Gray,
TitleColor = Color.DarkBlue
};
string title = "AI Assistant";
string subTitle = "Powered by OpenAI";
sfAIAssistView1.SetBannerView(title, subTitle,
Image.FromFile(@"Assets\ai-icon.png"), customStyle);sfAIAssistView1.PromptRequest += (sender, e) =>
{
var message = e.Message as TextMessage;
if (message == null) return;
// Validate input
if (string.IsNullOrWhiteSpace(message.Text))
{
e.Handled = true; // Prevent adding to messages
MessageBox.Show("Please enter a message.");
return;
}
// Custom processing
LogUserInput(message.Text);
};| Property/Method | Type | Description |
|---|---|---|
| ObservableCollection<object> | Chat message collection |
| IEnumerable<string> | Response suggestion items |
| bool | Shows/hides typing indicator |
| TypingIndicator | Typing indicator configuration |
| Author | Current user information |
| Method | Customize banner appearance |
| Method | Set custom bot message view |
| Method | Set custom user message view |
| Event | Fires when user submits prompt |
Install-Package Syncfusion.SfAIAssistView.WinFormsInstall-Package Microsoft.SemanticKernelShowTypingIndicator = trueTypingIndicator.Author