views:

32

answers:

1

I have a class called Cell with two properties. One is called Value of type int? And the other is called Candidates of type ObservableCollection<ObservableCollection<Candidate>>

during the initialization I am utilizing a DataTemplateSelector to choose between two datatemplates for two different scenarios.

If the Value property has a value then template A should be used to present the Cell class. However if the Value property is null Then template B should be used to present the Cell class.

While this works perfectly fine during the initialization however during the runtime the templates don't change any more when the value of the Value property actually changes.

Is the approach of using DataTemplateSelector the wrong approach to change DataTemplates dynamically? What would you recommend I should do?

Many thanks,

+2  A: 

While it seems like the DataTemplateSelector approach should work, another way to try would be to use a DataTrigger instead. You could create a style that triggers when the Value is null, and set the template of the control based on that value.

Andy
That's pretty much the right approach nothing more for me to add.
Mike Brown