Skip to content

Commit ba1816b

Browse files
Merge pull request #1507 from syncfusion-content/ES_1034350
Task 1034350: Prepare User Guide for Response Toolbar and Stop Responding Features in WinForms SfAIAssistView
2 parents d5db176 + 0bea126 commit ba1816b

7 files changed

Lines changed: 285 additions & 0 deletions

WindowsForms-toc.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4262,6 +4262,12 @@
42624262
<li>
42634263
<a href="/windowsforms/AI-AssistView/typing-indicator">Typing Indicator</a>
42644264
</li>
4265+
<li>
4266+
<a href="/windowsforms/AI-AssistView/stop-responding">Stop-Responding</a>
4267+
</li>
4268+
<li>
4269+
<a href="/windowsforms/AI-AssistView/response-toolbar">Response-ToolBar</a>
4270+
</li>
42654271
<li>
42664272
<a href="/windowsforms/AI-AssistView/events">Events</a>
42674273
</li>
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
layout: post
3+
title: Response Toolbar in Windows Forms AI AssistView control | Syncfusion
4+
description: Learn about the Response Toolbar in AI AssistView, letting users interact with bot replies using copy, regenerate, like, and custom action buttons.
5+
platform: windowsforms
6+
control: SfAIAssistView
7+
documentation: ug
8+
---
9+
10+
# Response ToolBar in WinForms AI AssistView
11+
12+
The **SfAIAssistView** control includes a **Response Toolbar** feature that allows users to perform actions on bot responses by clicking action buttons. This feature provides an interactive way for users to engage with AI responses through copy, regenerate, like, and other custom actions.
13+
14+
By default, the **Response Toolbar** is not displayed. To enable it, set the **IsResponseToolBarVisible** property to `true`.
15+
16+
{% tabs %}
17+
18+
{% highlight c# %}
19+
20+
SfAIAssistView sfAIAssistView1 = new SfAIAssistView();
21+
sfAIAssistView1.IsResponseToolBarVisible = true;
22+
23+
{% endhighlight %}
24+
25+
{% endtabs %}
26+
![WindowsForms AI AssistView control Response ToolBar](aiassistview_images/windowsforms_aiassistview_responsetoolbar.png)
27+
28+
29+
## Response Toolbar Items
30+
31+
The **Response Toolbar** supports the following action buttons:
32+
33+
- **Copy** - Copies the bot response text to clipboard
34+
- **Regenerate** - Regenerates the response for the same prompt
35+
- **Like** - Marks the response as helpful/liked
36+
- **Dislike** - Marks the response as not helpful
37+
- **Custom** - User-defined custom actions
38+
39+
## Response Toolbar Item Click Event
40+
41+
The **SfAIAssistView** control provides the **ResponseToolBarItemClicked** event. This is triggered when a user clicks any toolbar action button. You can handle these actions to perform specific operations based on the toolbar item clicked.
42+
43+
### Event Handler Code Example
44+
45+
{% tabs %}
46+
47+
{% highlight c# %}
48+
49+
sfAIAssistView1.ResponseToolBarItemClicked += sfAIAssistView1_ResponseToolBarItemClicked;
50+
51+
private void sfAIAssistView1_ResponseToolBarItemClicked(
52+
object sender,
53+
ResponseToolBarItemClickedEventArgs e)
54+
{
55+
// Handle the toolbar item click
56+
if (e.ToolBarItem.ItemType == ResponseToolBarItemType.Copy)
57+
{
58+
Clipboard.SetText(e.ChatItem.Text);
59+
MessageBox.Show("Message copied to clipboard!");
60+
}
61+
else if (e.ToolBarItem.ItemType == ResponseToolBarItemType.Regenerate)
62+
{
63+
MessageBox.Show("Regenerating response...");
64+
// Handle regeneration logic
65+
}
66+
else if (e.ToolBarItem.ItemType == ResponseToolBarItemType.Like)
67+
{
68+
MessageBox.Show("Response marked as helpful!");
69+
}
70+
}
71+
72+
{% endhighlight %}
73+
74+
{% endtabs %}
75+
76+
The **ResponseToolBarItemClickedEventArgs** provides access to the **ChatItem** (the message being acted upon) and the **ToolBarItem** (the action button clicked).
77+
78+
## Customization
79+
80+
### Controlling Toolbar Visibility
81+
82+
You can control the visibility of the entire toolbar or individual toolbar items:
83+
84+
{% tabs %}
85+
86+
{% highlight c# %}
87+
88+
var messagesList = sfAIAssistView1.Messages as IList;
89+
if(messagesList != null && messagesList.Count>0 )
90+
{
91+
var message = messagesList[1] as TextMessage;
92+
// Hide the entire toolbar for a specific message
93+
sfAIAssistView1.SetToolBarVisibility(message, false);
94+
95+
// Show the toolbar for a specific message
96+
sfAIAssistView1.SetToolBarVisibility(message, true);
97+
98+
// Hide a specific toolbar item for a message
99+
sfAIAssistView1.SetToolBarItemVisibility(
100+
message,
101+
ResponseToolBarItemType.Regenerate.ToString(),
102+
false);
103+
104+
// Hide toolbar item by name
105+
sfAIAssistView1.SetToolBarItemVisibility(message, "Copy", false);
106+
}
107+
108+
{% endhighlight %}
109+
110+
{% endtabs %}
111+
112+
### Getting Toolbar Items
113+
114+
Retrieve toolbar items from a message:
115+
116+
{% tabs %}
117+
118+
{% highlight c# %}
119+
120+
// Get a specific toolbar item
121+
ResponseToolBarItem copyButton = sfAIAssistView1.GetToolBarItem(
122+
message,
123+
ResponseToolBarItemType.Copy.ToString());
124+
125+
if (copyButton != null)
126+
{
127+
// Use toolbar item properties
128+
string itemName = copyButton.Name;
129+
}
130+
131+
{% endhighlight %}
132+
133+
{% endtabs %}
134+
135+
### Configuring Toolbar Items
136+
137+
Set custom toolbar items in the control:
138+
139+
{% tabs %}
140+
141+
{% highlight c# %}
142+
143+
// Configure toolbar items
144+
sfAIAssistView1.ResponseToolBarItems = new ObservableCollection<ResponseToolBarItem>
145+
{
146+
new ResponseToolBarItem
147+
{
148+
ItemType = ResponseToolBarItemType.Copy,
149+
Name = "Copy"
150+
},
151+
new ResponseToolBarItem
152+
{
153+
ItemType = ResponseToolBarItemType.Regenerate,
154+
Name = "Regenerate"
155+
},
156+
new ResponseToolBarItem
157+
{
158+
ItemType = ResponseToolBarItemType.Like,
159+
Name = "Like"
160+
}
161+
};
162+
163+
{% endhighlight %}
164+
165+
{% endtabs %}
166+
167+
168+
### How to hide Regenerate Button for Old Messages.
169+
170+
{% tabs %}
171+
172+
{% highlight c# %}
173+
174+
private void UpdateToolbarForLatestMessage()
175+
{
176+
var messages = (sfAIAssistView1.Messages as IList)
177+
?.Cast<TextMessage>().ToList();
178+
179+
if (messages == null) return;
180+
181+
var botMessages = messages
182+
.Where(m => m.Author.Name == "Bot")
183+
.ToList();
184+
185+
var latestMessage = botMessages.LastOrDefault();
186+
187+
// Hide Regenerate button on all old bot messages
188+
foreach (var oldMessage in botMessages
189+
.Where(m => m != latestMessage))
190+
{
191+
sfAIAssistView1.SetToolBarItemVisibility(
192+
oldMessage,
193+
ResponseToolBarItemType.Regenerate.ToString(),
194+
false);
195+
}
196+
}
197+
198+
{% endhighlight %}
199+
200+
{% endtabs %}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
layout: post
3+
title: Stop Responding in Windows Forms AI AssistView control | Syncfusion
4+
description: Learn about the Stop Responding feature in the AI AssistView control that allows users to cancel an ongoing AI response by clicking the Stop Responding button.
5+
platform: windowsforms
6+
control: SfAIAssistView
7+
documentation: ug
8+
---
9+
10+
# Stop Responding in WinForms AI AssistView
11+
12+
The **SfAIAssistView** control includes a **Stop Responding** feature that allows users to cancel an ongoing AI response by clicking the **Stop Responding** button. This feature ensures that users can interrupt the response if it is no longer needed.
13+
14+
By default, the **Stop Responding** button is not displayed. To enable it, set the EnableStopResponding property to `true`.
15+
16+
{% tabs %}
17+
18+
{% highlight c# %}
19+
20+
SfAIAssistView sfAIAssistView1 = new SfAIAssistView();
21+
sfAIAssistView1.EnableStopResponding = true;
22+
23+
{% endhighlight %}
24+
25+
{% endtabs %}
26+
![WindowsForms AI AssistView control StopResponding](aiassistview_images/windowsforms_aiassistview_stopresponding.png)
27+
28+
The button displays when EnableStopResponding is true.
29+
30+
## Stop Responding Event
31+
32+
The **SfAIAssistView** control provides the **StopRespondingButtonClicked** event. This is triggered when the **Stop Responding** button is clicked. You can handle this action to stop an ongoing AI response by subscribing to the **StopRespondingButtonClicked** event:
33+
34+
{% tabs %}
35+
36+
{% highlight c# %}
37+
38+
sfAIAssistView1.StopRespondingButtonClicked += SfaiAssistView1_StopResponding;
39+
40+
private void SfaiAssistView1_StopResponding(object sender, EventArgs e)
41+
{
42+
// Handle the Stop Responding action
43+
CancelAIRequest();
44+
}
45+
46+
private System.Threading.CancellationTokenSource cts;
47+
public void CancelAIRequest()
48+
{
49+
if (cts != null && !cts.IsCancellationRequested)
50+
cts.Cancel();
51+
}
52+
53+
{% endhighlight %}
54+
55+
{% endtabs %}
56+
![WindowsForms AI AssistView control Cancel StopResponding](aiassistview_images/windowsforms_aiassistview_canceling.png)
57+
58+
## Customization
59+
60+
The button text and hold duration in **SfAIAssistView** can be customized using the **StopRespondingButtonText**, **StopRespondingButtonCancelingText**, and **StopRespondingHoldSeconds** properties. This allows you to set the button text, canceling text, and hold time for the **Stop Responding** button.
61+
62+
{% tabs %}
63+
64+
{% highlight c# %}
65+
66+
// Set button text
67+
sfAIAssistView1.StopRespondingButtonText = "⏹ Stop";
68+
69+
// Set canceling text (shown while canceling)
70+
sfAIAssistView1.StopRespondingButtonCancelingText = "Stopping...";
71+
72+
// Set hold time (seconds button stays disabled after click)
73+
sfAIAssistView1.StopRespondingHoldSeconds = 2;
74+
75+
{% endhighlight %}
76+
77+
{% endtabs %}
78+
![WindowsForms AI AssistView control StopRespondingButtonText](aiassistview_images/windowsforms_aiassistview_stoprespondingtext.png)
79+
75.2 KB
Loading
74.9 KB
Loading
74.5 KB
Loading
73.9 KB
Loading

0 commit comments

Comments
 (0)