Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions WindowsForms-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -4262,6 +4262,12 @@
<li>
<a href="/windowsforms/AI-AssistView/typing-indicator">Typing Indicator</a>
</li>
<li>
<a href="/windowsforms/AI-AssistView/stop-responding">Stop-Responding</a>
</li>
<li>
<a href="/windowsforms/AI-AssistView/response-toolbar">Response-ToolBar</a>
</li>
<li>
<a href="/windowsforms/AI-AssistView/events">Events</a>
</li>
Expand Down
200 changes: 200 additions & 0 deletions WindowsForms/AI-AssistView/Response-ToolBar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
---
layout: post
title: Response Toolbar in Windows Forms AI AssistView control | Syncfusion
description: Learn about the Response Toolbar in AI AssistView, letting users interact with bot replies using copy, regenerate, like, and custom action buttons.
platform: windowsforms
control: SfAIAssistView
documentation: ug
---

# Response ToolBar in WinForms AI AssistView

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.

By default, the **Response Toolbar** is not displayed. To enable it, set the **IsResponseToolBarVisible** property to `true`.

{% tabs %}

{% highlight c# %}

SfAIAssistView sfAIAssistView1 = new SfAIAssistView();
sfAIAssistView1.IsResponseToolBarVisible = true;

{% endhighlight %}

{% endtabs %}
![WindowsForms AI AssistView control Response ToolBar](aiassistview_images/windowsforms_aiassistview_responsetoolbar.png)


## Response Toolbar Items

The **Response Toolbar** supports the following action buttons:

- **Copy** - Copies the bot response text to clipboard
- **Regenerate** - Regenerates the response for the same prompt
- **Like** - Marks the response as helpful/liked
- **Dislike** - Marks the response as not helpful
- **Custom** - User-defined custom actions

## Response Toolbar Item Click Event

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.

### Event Handler Code Example

{% tabs %}

{% highlight c# %}

sfAIAssistView1.ResponseToolBarItemClicked += sfAIAssistView1_ResponseToolBarItemClicked;

private void sfAIAssistView1_ResponseToolBarItemClicked(
object sender,
ResponseToolBarItemClickedEventArgs e)
{
// Handle the toolbar item click
if (e.ToolBarItem.ItemType == ResponseToolBarItemType.Copy)
{
Clipboard.SetText(e.ChatItem.Text);
MessageBox.Show("Message copied to clipboard!");
}
else if (e.ToolBarItem.ItemType == ResponseToolBarItemType.Regenerate)
{
MessageBox.Show("Regenerating response...");
// Handle regeneration logic
}
else if (e.ToolBarItem.ItemType == ResponseToolBarItemType.Like)
{
MessageBox.Show("Response marked as helpful!");
}
}

{% endhighlight %}

{% endtabs %}

The **ResponseToolBarItemClickedEventArgs** provides access to the **ChatItem** (the message being acted upon) and the **ToolBarItem** (the action button clicked).

## Customization

### Controlling Toolbar Visibility

You can control the visibility of the entire toolbar or individual toolbar items:

{% tabs %}

{% highlight c# %}

var messagesList = sfAIAssistView1.Messages as IList;
if(messagesList != null && messagesList.Count>0 )
{
var message = messagesList[1] as TextMessage;
// Hide the entire toolbar for a specific message
sfAIAssistView1.SetToolBarVisibility(message, false);

// Show the toolbar for a specific message
sfAIAssistView1.SetToolBarVisibility(message, true);

// Hide a specific toolbar item for a message
sfAIAssistView1.SetToolBarItemVisibility(
message,
ResponseToolBarItemType.Regenerate.ToString(),
false);

// Hide toolbar item by name
sfAIAssistView1.SetToolBarItemVisibility(message, "Copy", false);
}

{% endhighlight %}

{% endtabs %}

### Getting Toolbar Items

Retrieve toolbar items from a message:

{% tabs %}

{% highlight c# %}

// Get a specific toolbar item
ResponseToolBarItem copyButton = sfAIAssistView1.GetToolBarItem(
message,
ResponseToolBarItemType.Copy.ToString());

if (copyButton != null)
{
// Use toolbar item properties
string itemName = copyButton.Name;
}

{% endhighlight %}

{% endtabs %}

### Configuring Toolbar Items

Set custom toolbar items in the control:

{% tabs %}

{% highlight c# %}

// Configure toolbar items
sfAIAssistView1.ResponseToolBarItems = new ObservableCollection<ResponseToolBarItem>
{
new ResponseToolBarItem
{
ItemType = ResponseToolBarItemType.Copy,
Name = "Copy"
},
new ResponseToolBarItem
{
ItemType = ResponseToolBarItemType.Regenerate,
Name = "Regenerate"
},
new ResponseToolBarItem
{
ItemType = ResponseToolBarItemType.Like,
Name = "Like"
}
};

{% endhighlight %}

{% endtabs %}


### How to hide Regenerate Button for Old Messages.

{% tabs %}

{% highlight c# %}

private void UpdateToolbarForLatestMessage()
{
var messages = (sfAIAssistView1.Messages as IList)
?.Cast<TextMessage>().ToList();

if (messages == null) return;

var botMessages = messages
.Where(m => m.Author.Name == "Bot")
.ToList();

var latestMessage = botMessages.LastOrDefault();

// Hide Regenerate button on all old bot messages
foreach (var oldMessage in botMessages
.Where(m => m != latestMessage))
{
sfAIAssistView1.SetToolBarItemVisibility(
oldMessage,
ResponseToolBarItemType.Regenerate.ToString(),
false);
}
}

{% endhighlight %}

{% endtabs %}
79 changes: 79 additions & 0 deletions WindowsForms/AI-AssistView/Stop-Responding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
layout: post
title: Stop Responding in Windows Forms AI AssistView control | Syncfusion
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.
platform: windowsforms
control: SfAIAssistView
documentation: ug
---

# Stop Responding in WinForms AI AssistView

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.

By default, the **Stop Responding** button is not displayed. To enable it, set the EnableStopResponding property to `true`.

{% tabs %}

{% highlight c# %}

SfAIAssistView sfAIAssistView1 = new SfAIAssistView();
sfAIAssistView1.EnableStopResponding = true;

{% endhighlight %}

{% endtabs %}
![WindowsForms AI AssistView control StopResponding](aiassistview_images/windowsforms_aiassistview_stopresponding.png)

The button displays when EnableStopResponding is true.

## Stop Responding Event

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:

{% tabs %}

{% highlight c# %}

sfAIAssistView1.StopRespondingButtonClicked += SfaiAssistView1_StopResponding;

private void SfaiAssistView1_StopResponding(object sender, EventArgs e)
{
// Handle the Stop Responding action
CancelAIRequest();
}

private System.Threading.CancellationTokenSource cts;
public void CancelAIRequest()
{
if (cts != null && !cts.IsCancellationRequested)
cts.Cancel();
}

{% endhighlight %}

{% endtabs %}
![WindowsForms AI AssistView control Cancel StopResponding](aiassistview_images/windowsforms_aiassistview_canceling.png)

## Customization

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.

{% tabs %}

{% highlight c# %}

// Set button text
sfAIAssistView1.StopRespondingButtonText = "⏹ Stop";

// Set canceling text (shown while canceling)
sfAIAssistView1.StopRespondingButtonCancelingText = "Stopping...";

// Set hold time (seconds button stays disabled after click)
sfAIAssistView1.StopRespondingHoldSeconds = 2;

{% endhighlight %}

{% endtabs %}
![WindowsForms AI AssistView control StopRespondingButtonText](aiassistview_images/windowsforms_aiassistview_stoprespondingtext.png)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.