syncfusion-wpf-ai-assistview
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing SfAIAssistView (WPF)
实现SfAIAssistView(WPF)
When to Use This Skill
何时使用本技能
Use this skill when:
- Building AI chat or assistant UIs in WPF
- Displaying message threads with user and AI responses
- Integrating OpenAI or SemanticKernel with a chat interface
- Showing typing indicators while AI processes a response
- Adding suggestion chips after AI responses
- Customizing input/response toolbars
- Handling events or Stop Responding functionality
PromptRequest - Rendering Markdown in AI responses via
ViewTemplateSelector
NuGet Package:
Namespace:
Key Classes: , , , ,
Syncfusion.SfChat.WpfSyncfusion.UI.Xaml.ChatSfAIAssistViewTextMessageAIMessageAuthorTypingIndicator在以下场景使用本技能:
- 在WPF中构建AI聊天或助手UI
- 显示包含用户和AI回复的消息线程
- 将OpenAI或SemanticKernel与聊天界面集成
- 在AI处理回复时显示输入指示器
- 在AI回复后添加建议芯片
- 自定义输入/回复工具栏
- 处理事件或停止回复功能
PromptRequest - 通过在AI回复中渲染Markdown
ViewTemplateSelector
NuGet包:
命名空间:
核心类: , , , ,
Syncfusion.SfChat.WpfSyncfusion.UI.Xaml.ChatSfAIAssistViewTextMessageAIMessageAuthorTypingIndicatorQuick Start
快速开始
xaml
<!-- MainWindow.xaml -->
<Window xmlns:syncfusion="clr-namespace:Syncfusion.UI.Xaml.Chat;assembly=Syncfusion.SfChat.WPF">
<Grid>
<Grid.DataContext>
<local:ViewModel/>
</Grid.DataContext>
<syncfusion:SfAIAssistView
Messages="{Binding Chats}"
CurrentUser="{Binding CurrentUser}"
Suggestions="{Binding Suggestions}"
ShowTypingIndicator="{Binding ShowTypingIndicator}"
TypingIndicator="{Binding TypingIndicator}" />
</Grid>
</Window>csharp
// ViewModel.cs
public class ViewModel : INotifyPropertyChanged
{
public ObservableCollection<object> Chats { get; set; }
public Author CurrentUser { get; set; }
public ViewModel()
{
Chats = new ObservableCollection<object>();
CurrentUser = new Author { Name = "User" };
Chats.Add(new TextMessage
{
Author = CurrentUser,
Text = "Hello, how can you help me?"
});
Chats.Add(new TextMessage
{
Author = new Author { Name = "AI" },
Text = "I can answer questions and help with tasks."
});
}
}xaml
<!-- MainWindow.xaml -->
<Window xmlns:syncfusion="clr-namespace:Syncfusion.UI.Xaml.Chat;assembly=Syncfusion.SfChat.WPF">
<Grid>
<Grid.DataContext>
<local:ViewModel/>
</Grid.DataContext>
<syncfusion:SfAIAssistView
Messages="{Binding Chats}"
CurrentUser="{Binding CurrentUser}"
Suggestions="{Binding Suggestions}"
ShowTypingIndicator="{Binding ShowTypingIndicator}"
TypingIndicator="{Binding TypingIndicator}" />
</Grid>
</Window>csharp
// ViewModel.cs
public class ViewModel : INotifyPropertyChanged
{
public ObservableCollection<object> Chats { get; set; }
public Author CurrentUser { get; set; }
public ViewModel()
{
Chats = new ObservableCollection<object>();
CurrentUser = new Author { Name = "User" };
Chats.Add(new TextMessage
{
Author = CurrentUser,
Text = "Hello, how can you help me?"
});
Chats.Add(new TextMessage
{
Author = new Author { Name = "AI" },
Text = "I can answer questions and help with tasks."
});
}
}Documentation and Navigation Guide
文档与导航指南
Getting Started
入门指南
📄 Read: references/getting-started.md
- NuGet installation and assembly references
- XAML namespace and control declaration
- ViewModel setup with
ObservableCollection<object> - +
TextMessagebinding patternAuthor - configuration
CurrentUser - Theme integration
📄 阅读: references/getting-started.md
- NuGet安装与程序集引用
- XAML命名空间与控件声明
- 使用设置ViewModel
ObservableCollection<object> - +
TextMessage绑定模式Author - 配置
CurrentUser - 主题集成
OpenAI Integration
OpenAI集成
📄 Read: references/openai-integration.md
- NuGet setup
Microsoft.SemanticKernel - +
IChatCompletionServiceconfigurationKernel - pattern for async responses
AIAssistChatService - trigger to invoke AI calls
CollectionChanged - with
AIMessage(AI icon)ContentTemplate - for Markdown rendering via MdXaml
ViewTemplateSelector - Coordinating with async operations
ShowTypingIndicator
📄 阅读: references/openai-integration.md
- NuGet设置
Microsoft.SemanticKernel - +
IChatCompletionService配置Kernel - 用于异步回复的模式
AIAssistChatService - 触发AI调用的事件
CollectionChanged - 带(AI图标)的
ContentTemplateAIMessage - 通过MdXaml实现Markdown渲染的
ViewTemplateSelector - 异步操作中协调
ShowTypingIndicator
Suggestions & Typing Indicator
建议功能与输入指示器
📄 Read: references/suggestions-and-typing-indicator.md
- property (
Suggestions) bindingIEnumerable<string> - Updating suggestion chips after AI response
- object setup in ViewModel
TypingIndicator - property
ShowTypingIndicator - Toggling indicator on/off with async AI calls
📄 阅读: references/suggestions-and-typing-indicator.md
- 属性(
Suggestions)绑定IEnumerable<string> - AI回复后更新建议芯片
- ViewModel中的对象设置
TypingIndicator - 属性
ShowTypingIndicator - 通过异步AI调用切换指示器的显示/隐藏
Input Toolbar
输入工具栏
📄 Read: references/input-toolbar.md
- property
IsInputToolbarVisible - (Left/Right)
InputToolbarPosition - (ItemTemplate, IsEnabled, Tooltip, Visible)
InputToolbarItem - event handling
InputToolbarItemClicked - for file-upload-style headers
InputToolbarHeaderTemplate
📄 阅读: references/input-toolbar.md
- 属性
IsInputToolbarVisible - (左/右)
InputToolbarPosition - (ItemTemplate、IsEnabled、Tooltip、Visible)
InputToolbarItem - 事件处理
InputToolbarItemClicked - 用于文件上传样式头部的
InputToolbarHeaderTemplate
Response Toolbar
回复工具栏
📄 Read: references/response-toolbar.md
- property
IsResponseToolbarVisible - Built-in toolbar items: Copy, Regenerate, Like, Dislike
- with
ResponseToolbarItem,Index,ItemTypeItemTemplate - event handling
ResponseToolbarItemClicked - Custom item template examples
📄 阅读: references/response-toolbar.md
- 属性
IsResponseToolbarVisible - 内置工具栏项:复制、重新生成、点赞、点踩
- 带、
Index、ItemType的ItemTemplateResponseToolbarItem - 事件处理
ResponseToolbarItemClicked - 自定义项模板示例
Events & Stop Responding
事件与停止回复
📄 Read: references/events-and-stop-responding.md
- event +
PromptRequestPromptRequestEventArgs - and
InputMessageproperty patternHandled - property
EnableStopResponding - event and
StopResponding(MVVM)StopRespondingCommand - customization
StopRespondingTemplate
📄 阅读: references/events-and-stop-responding.md
- 事件 +
PromptRequestPromptRequestEventArgs - 与
InputMessage属性模式Handled - 属性
EnableStopResponding - 事件与
StopResponding(MVVM)StopRespondingCommand - 自定义
StopRespondingTemplate
Key Properties
核心属性
| Property | Type | Purpose |
|---|---|---|
| | Chat message collection |
| | Identifies the local user |
| | Suggestion chips shown after AI response |
| | Shows/hides typing animation |
| | Typing indicator with Author |
| | Shows custom input toolbar (default: false) |
| | Shows response toolbar (default: true) |
| | Enables Stop Responding button (default: false) |
| | Custom rendering per message type |
| 属性 | 类型 | 用途 |
|---|---|---|
| | 聊天消息集合 |
| | 标识本地用户 |
| | AI回复后显示的建议芯片 |
| | 显示/隐藏输入动画 |
| | 带作者信息的输入指示器 |
| | 显示自定义输入工具栏(默认:false) |
| | 显示回复工具栏(默认:true) |
| | 启用停止回复按钮(默认:false) |
| | 按消息类型自定义渲染 |
Common Patterns
常见模式
User sends message → AI responds
用户发送消息 → AI回复
csharp
// Subscribe to CollectionChanged on Chats
Chats.CollectionChanged += async (s, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Add
&& e.NewItems[0] is TextMessage msg
&& msg.Author.Name == CurrentUser.Name)
{
ShowTypingIndicator = true;
var reply = await aiService.GetResponseAsync(msg.Text);
Chats.Add(new AIMessage { Author = aiAuthor, Text = reply });
ShowTypingIndicator = false;
}
};csharp
// 订阅Chats的CollectionChanged事件
Chats.CollectionChanged += async (s, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Add
&& e.NewItems[0] is TextMessage msg
&& msg.Author.Name == CurrentUser.Name)
{
ShowTypingIndicator = true;
var reply = await aiService.GetResponseAsync(msg.Text);
Chats.Add(new AIMessage { Author = aiAuthor, Text = reply });
ShowTypingIndicator = false;
}
};Adding suggestions after AI response
AI回复后添加建议
csharp
Suggestions = new List<string> { "Tell me more", "Give an example", "Summarize" };csharp
Suggestions = new List<string> { "Tell me more", "Give an example", "Summarize" };Handling PromptRequest event
处理PromptRequest事件
xaml
<syncfusion:SfAIAssistView PromptRequest="OnPromptRequest" />csharp
private void OnPromptRequest(object sender, PromptRequestEventArgs e)
{
// e.InputMessage contains the user's text
e.Handled = true; // Prevent default processing
}xaml
<syncfusion:SfAIAssistView PromptRequest="OnPromptRequest" />csharp
private void OnPromptRequest(object sender, PromptRequestEventArgs e)
{
// e.InputMessage包含用户输入的文本
e.Handled = true; // 阻止默认处理
}