Loading...
Loading...
Compare original and translation side by side
PromptRequestViewTemplateSelectorSyncfusion.SfChat.WpfSyncfusion.UI.Xaml.ChatSfAIAssistViewTextMessageAIMessageAuthorTypingIndicatorPromptRequestViewTemplateSelectorSyncfusion.SfChat.WpfSyncfusion.UI.Xaml.ChatSfAIAssistViewTextMessageAIMessageAuthorTypingIndicator<!-- 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>// 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."
});
}
}<!-- 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>// 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."
});
}
}ObservableCollection<object>TextMessageAuthorCurrentUserObservableCollection<object>TextMessageAuthorCurrentUserMicrosoft.SemanticKernelIChatCompletionServiceKernelAIAssistChatServiceCollectionChangedAIMessageContentTemplateViewTemplateSelectorShowTypingIndicatorMicrosoft.SemanticKernelIChatCompletionServiceKernelAIAssistChatServiceCollectionChangedContentTemplateAIMessageViewTemplateSelectorShowTypingIndicatorSuggestionsIEnumerable<string>TypingIndicatorShowTypingIndicatorSuggestionsIEnumerable<string>TypingIndicatorShowTypingIndicatorIsInputToolbarVisibleInputToolbarPositionInputToolbarItemInputToolbarItemClickedInputToolbarHeaderTemplateIsInputToolbarVisibleInputToolbarPositionInputToolbarItemInputToolbarItemClickedInputToolbarHeaderTemplateIsResponseToolbarVisibleResponseToolbarItemIndexItemTypeItemTemplateResponseToolbarItemClickedIsResponseToolbarVisibleIndexItemTypeItemTemplateResponseToolbarItemResponseToolbarItemClickedPromptRequestPromptRequestEventArgsInputMessageHandledEnableStopRespondingStopRespondingStopRespondingCommandStopRespondingTemplatePromptRequestPromptRequestEventArgsInputMessageHandledEnableStopRespondingStopRespondingStopRespondingCommandStopRespondingTemplate| 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) |
| | 按消息类型自定义渲染 |
// 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;
}
};// 订阅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;
}
};Suggestions = new List<string> { "Tell me more", "Give an example", "Summarize" };Suggestions = new List<string> { "Tell me more", "Give an example", "Summarize" };<syncfusion:SfAIAssistView PromptRequest="OnPromptRequest" />private void OnPromptRequest(object sender, PromptRequestEventArgs e)
{
// e.InputMessage contains the user's text
e.Handled = true; // Prevent default processing
}<syncfusion:SfAIAssistView PromptRequest="OnPromptRequest" />private void OnPromptRequest(object sender, PromptRequestEventArgs e)
{
// e.InputMessage包含用户输入的文本
e.Handled = true; // 阻止默认处理
}