New to Telerik UI for .NET MAUI? Start a free 30-day trial

.NET MAUI Chat Commands

The Telerik UI for .NET MAUI Chat allows you to attach commands that will be executed when certain actions such as SendMessage occur.

Chat Commands

Take advantage of the SendMessageCommand that is triggered when the send-message button is clicked or when the user presses the Enter key on desktop platforms. The command is raised before the Chat auto-creates a ChatItem and adds it to the Items collection.

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

1. Add the command's Execute method.

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

2. Define the RadChat component:

<telerik:RadChat x:Name="chat"
                ItemsSource="{Binding Items}"
                SendMessageCommand="{Binding NewMessageCommand}"/>

3. Add the ViewModel:

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

    this.MessagesLog = new ObservableCollection<LogItem>();

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

See Also

In this article