Вопрос

I have ItemsControl with multi DataTemplate and use ItemTemplateSelector to chose appropriate DataTemplate of each item of ItemsSource. I want to binding ItemTemplateSelector to TemplateType dependency property of item. and each time TemplateType property changed, DataTemplate change automaticaly. How can I do.

Это было полезно?

Решение

I Search about own question. and find below code to refresh ItemTemplateSelector :

DataTemplateSelector DataTemplateSelector = plan.ItemTemplateSelector;
plan.ItemTemplateSelector = null;
plan.ItemTemplateSelector = DataTemplateSelector;

Другие советы

I'd go for a different solution in your case, if you want to update the datatemplate. I would create a binding to the ItemTemplate of your ItemsControl. That binding gets a converter assigned, which contains the logic of your current ItemTemplateSelector. And the source of the binding is your TemplateType property.

The ItemTemplateSelector is just for one-shot evaluation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top