Skip to content

Commit 5ba7773

Browse files
Task 1034350: Prepare User Guide for Response Toolbar and Stop Responding Features in WinForms SfAIAssistView
1 parent d5db176 commit 5ba7773

7 files changed

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

0 commit comments

Comments
 (0)