I have a class ca开发者_如何学Golled 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,
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.
精彩评论