New to Telerik UI for Xamarin? Download free 30-day trial

Commands

RadChat allows you to attach commands that will be executed when certain actions such as SendMessage occur.

Before proceeding check the MVVM Support topic for more details on how to use RadChat in a MVVM setup.

Chat Commands

You could take advantage of the SendMessageCommand that is triggered by two actions when the send-message button is clicked. The command is raised before the Chat auto-creates a ChatItem and adds it to the Items.

Here is a quick example on how to define a command in the ViewModel and bind the SendMessageCommand to it:

public ViewModel()
{
    this.Items = new ObservableCollection<ChatItem>();
    this.NewMessageCommand = new Command(NewMessageCommandExecute);

    this.MessagesLog = new ObservableCollection<string>();
}

public ObservableCollection<string> MessagesLog { get; set; }
public ICommand NewMessageCommand { get; set; }
public IList<ChatItem> Items { get; set; }

And the command Execute method:

private void NewMessageCommandExecute(object obj)
{
    var newMessage = (string)obj;
    //any additional logic you need to implement    
    this.MessagesLog.Add("You just added a new message with text " + newMessage);
}

Following the definition of RadChat components:

<telerikConversationalUI:RadChat x:Name="chat"
                Grid.Row="1"
                ItemsSource="{Binding Items}"                            
                SendMessageCommand="{Binding NewMessageCommand}" />

ChatPicker Commands

RadChatPicker control exposes OkCommand and CancelCommand fired when the corresponding "Ok" and "Cancel" buttons are clicked.

See Also

In this article