TimeBreak at start of Chat messages

0 Answers 22 Views
Chat (Conversational UI)
Max
Top achievements
Rank 1
Veteran
Iron
Max asked on 20 Mar 2025, 09:24 AM | edited on 20 Mar 2025, 09:25 AM

I'm using a RadChat in my project with a DataBinding to the ItemSource.

A MessageConverter creates either TextMessages or GifMessages. This all works fine.

The problem I have is that I want to add a TimeBreak to the top of the list, as I use the chat to store messages in my interface to view later, like a log. The first message can be in the past. And I want to know when this was.

My current solution is to always add one dummy message to  the top of the pile, which has a DateTime:  2000-01-01

I've added a Style to my App.Xaml:

 

 <Style BasedOn="{StaticResource InlineMessageControlStyle}" TargetType="conversationalUi:InlineMessageControl">
    <EventSetter Event="Loaded" Handler="InlineMessageControl_OnLoaded" />
 </Style>

This gives access to the loading of the InlineMessageControl. In which I look up the Message with the CreateAt of 2000-01-01. Like this:

 

private void InlineMessageControl_OnLoaded(object sender, RoutedEventArgs e)
{
  try
  {
    if (sender is not InlineMessageControl inlineMessageControl) { return; }

    //Hide first item, that is inserted manually to force a TimeBreak on the second
    if (inlineMessageControl.DataContext is InlineViewModel { CreationDate.Year: 2000 })
    {
      if (inlineMessageControl.TryFindParent<MessageGroup>() is { } messageGroup)
      {
        messageGroup.Visibility = Visibility.Collapsed;
      }

      if (inlineMessageControl.TryFindParent<VirtualizingStackPanel>() is { } panel)
      {
        panel.Margin = new Thickness(0, -15, 0, 0);
      }
    }
}

 

The result can be seen in the PNG attachment. However, I think this method should not be necesarry, as the tool itself should be able to do this using a bool like: AddTimeBreakToTop or something.

 

I am aware that you can add the Messages manually, but this seems like a even worse solution.

 

Waht are you thoughts, Am I missing something? Can this be improved?

 

Second question would be. How do I style the background of the TextMessages?

 

No answers yet. Maybe you can help?

Tags
Chat (Conversational UI)
Asked by
Max
Top achievements
Rank 1
Veteran
Iron
Share this question
or