Created
June 14, 2018 15:34
-
-
Save rdelrosario/b1348c5a28fea7ddf16ebeaa77d39d60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using ChatUIXForms.Models; | |
| using ChatUIXForms.Views.Cells; | |
| using Xamarin.Forms; | |
| namespace ChatUIXForms.Helpers | |
| { | |
| class ChatTemplateSelector : DataTemplateSelector | |
| { | |
| DataTemplate incomingDataTemplate; | |
| DataTemplate outgoingDataTemplate; | |
| public ChatTemplateSelector() | |
| { | |
| this.incomingDataTemplate = new DataTemplate(typeof(IncomingViewCell)); | |
| this.outgoingDataTemplate = new DataTemplate(typeof(OutgoingViewCell)); | |
| } | |
| protected override DataTemplate OnSelectTemplate(object item, BindableObject container) | |
| { | |
| var messageVm = item as Message; | |
| if (messageVm == null) | |
| return null; | |
| return (messageVm.User == App.User)? outgoingDataTemplate: incomingDataTemplate; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment