Chat data binding
When you describe in your documentation the SfChat data binding you created a MessageModel like this
public class MessageModel { public MessageModel() { } public ChatSuggestions Suggestions { get; set; } public Author User { get; set; } public string Text { get; set; } }
and then in the ViewModel, you created some MessageModel in this way
messageCollection.Add(new MessageModel() { User = currentAuthor, Text = "Hi guys, good morning! I'm very delighted to share with you the news that our team is going to launch a new mobile application.", });
and they are then converted to a TextMessage inside the MessageConverter class
Supposing the MessageModel is a class where I load information from a database so I have not only text messages but also Images to add to the Sfchat
Ho can I add the images in the sfchat from the ViewModel ?
In the database I have a field containing the path of the image but if I use this piece of code inside the Viewmodel
var byteArray = File.ReadAllBytes(chat.path);
ImageSource image = ImageSource.FromStream(() => new MemoryStream(byteArray));
ImageMessage r = new ImageMessage()
{
Author = CurrentUser,
Aspect = Aspect.AspectFit,
Source = image,
DateTime = chat.Data
};
how can I add it to the messageCollection ?
Hi Walter Martin,
We have checked your requirement , you can use the converter same as TextMessage , In model class , create a property for ImageMessage , which you can customize in converter, we have created a sample for your reference please have a look at the sample and let us know if you have any concern.
UG Link:https://help.syncfusion.com/maui/chat/data-binding
Regards,
Suthi Yuvaraj.
Attachment: MauiChat_931e139f.zip
It works perfectly, thanks
Walter Martin,
We are glad that the provided response meets your requirements. Please let us know if you need further assistance. As always, we are happy to help you out.
- 3 Replies
- 2 Participants
- Marked answer
-
WM Walter Martin
- May 1, 2024 10:09 PM UTC
- May 6, 2024 04:21 AM UTC