Thanks for getting back to me.
The Converters solution is also a good approach, especially in your case when the different data templates are identical in their structure.
As for the implementation with a Data Template selector I want to make the following remarks:
When you implement the INotifyPropertyChanged interface in your ViewModel and fire the PropertyChanged event upon updates, this impacts the bindings within
an existing Data Template assigned to the visual container which is currently associated with this ViewModel. In your particular scenario, you update a Template
property and fire the PropertyChanged
event but this property is not used within a DataTemplate
directly but by a DataTemplateSelector
which decides which template to select based on its value. Since the DataTemplateSelector
never subscribes for PropertyChanged
events exposed by the viewmodels (as it does not have access to them until after the ListBox is bound to a datasource), it cannot handle these changes.
I hope this puts some more clarity on how things currently work with DataTemplateSelectors.
Let me know should you have further questions.
Have a suggestion or face a problem - you can use the Ideas & Feedback portal
to submit ideas, feedback and vote for them.