New to Telerik UI for WinFormsStart a free 30-day trial

How to Format the Time Separator in RadChat

Updated over 6 months ago

Environment

Product VersionProductAuthor
2022.1.222RadChat for WinFormsDesislava Yordanova

Description

RadChat offers the ChatElement.MessagesViewElement.TimeSeparatorInterval property that controls the time interval between messages that will trigger the automatic addition of a Time separator. You can set this property to 24 hours in order to display the time separator once when the date has changed.

format-chat-time-separator 001

When a new message is added, the TimeSeparatorAdding event is fired. It gives you the opportunity to control whether to add a time separator or not no matter the already specified TimeSeparatorInterval.

A common requirement is to format the time separator in a specific way. This article demonstrates a sample approach how to control what text to be displayed for the time separator.

Solution

It is appropriate to use the ItemFormatting event and specify the exact text you want to see for the separator:

format-chat-time-separator 002

C#
private void RadChat1_ItemFormatting(object sender, ChatItemElementEventArgs e)
{
    ChatTimeSeparatorDataItem separator = e.ItemElement.Data as ChatTimeSeparatorDataItem;
    if (separator != null)
    {
        ChatTimeSeparatorMessage msg = separator.Message as ChatTimeSeparatorMessage;
        e.ItemElement.Text = msg.TimeStamp.ToString("dd-MM-yyyy");
    }
}
    

See Also