Sender reciever direction in sfChat custom template

Hi,

     I've followed the sample here https://github.com/SyncfusionExamples/Chat-Message-Template-Xamarin.Forms to build a custom template for a new message type, the thing is it doesn't consider the author ( all the messages are rendered the same way either from the current user or not. how to make it consider the direction


thanks


3 Replies 1 reply marked as answer

SV Suja Venkatesan Syncfusion Team January 27, 2022 03:31 PM UTC

Hi Amr, 
  
We would like to let you know that, for the custom message template of SfChat, we can load the incoming and outgoing messages based on message author in OnSelectTemplate method SfChat MessageTemplate selector as like below code snippets: 
  
Code Snippets: 
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) 
        { 
            var val = item as TextMessage; 
          
            if (item as TextMessage != null ) 
            { 
                if (val.Author == viewModel1.CurrentUser) 
                { 
                        return Outgoing_Template; 
                } 
  
                else if (val.Author != viewModel1.CurrentUser) 
                    return Incoming_Template;  
            } 
                return base.OnSelectTemplate(item, container); 
            
        } 
 
  
We have prepared a simple sample with custom message template and attached it in below sample link for you reference.   
  
Please let us know if you need any other further assistance. 
  
Regards, 
Suja 


Marked as answer

AY Amr Yousef February 10, 2022 09:52 AM UTC

It worked, thanks a lot for the remarkable support and speed, and sorry for my late response



SV Suja Venkatesan Syncfusion Team February 11, 2022 01:56 PM UTC

Hi Amr, 

We are glad that our solution meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out..   

Regards, 
Suja 


Loader.
Up arrow icon