Hi Korstiaan,
You're correct, TemplateSelectors by design do not listen for property changes and the templates do not get switched after it's been rendered. If you wanted to trigger the TemplateSelector to render an item with a different template, you would remove and re-add the item.
The resulting CollectionChanged event will trigger the TemplateSelector because a DataTemplate is needed for the item changes
Single DataTemplate Option
You've described the other good option with using a single item template. you can have a single DataTemplate that has UI elements for the different types of messages and show/hide/change parts of that template using properties of the message data model.
Using the same example from my earlier post, you can combine both ImageUrl and WebUrl in the same model and use a converter to show or hide the
and the converter looks something like this:
You could use a single DataTemplate like this:
The same concept applies for anything else, like BackgroundColor, showing/hiding icons, etc. The only thing you really need to be sure of is that you're invoking property changed in some way when that message gets updated.
For example, if you're just trying to update the values of a message that already exists, you can use the same approach I use above to locate the item:
PropertyChanged consideration
If you did try this and you're not seeing any changes, it would be because the property on the model is not invoking PropertyChanged notification. Otherwise the binding in the template isn't informed of the value change and any converters (i.e. bool to color converter) wouldn't be triggered.
If you're using our
Telerik.XamarinForms.ConversationalUI.TextMessage model as the base class, we already have INotifyPropertyChanged implemented. You can just call "OnPropertyChanged() in your property setters like I do above for ImageUrl and WebUrl.
Further Assistance
If you have trouble, please share your code and steps to reproduce with us in a Support Ticket. You have a priority support license and can use this link to open a new ticket -
Get Support (choose UI for Xamarin).
Tip - If you do open a ticket and your repro project isn't able to connect to the messaging service, please add some sample messages in the chat service logic (instead of trying to connect). This way we'll be able to directly see the data and provide a much faster time to solution.
Regards,
Lance | Technical Support Engineer, Principal
Progress Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items