Share via

Nested & Complex DataTemplates & ItemsControls

Nathan Sokalski 4,111 Reputation points
2020-07-08T22:39:13.717+00:00

I have several ItemsControls that contain nested ItemsControls (the DataTemplate contains another ItemsControl) or ItemTemplates (sometimes through an ItemTemplateSelector) that often contain IValueConverter(s) and other bindings. This is all very nice when doing the initial binding, but can sometimes hurt performance during runtime. If I do a complete rebinding every time any item changes, the app would be horribly slow, so I figured the best solution would be to manually modify the generated elements individually when necessary. I have tried to use the DataTemplateSelector.GetElement() and DataTemplate.LoadContent() methods, however, these cause the following challenges:

  1. Bindings & IValueConverters are not included or applied in the returned elements
  2. Finding the Panel to which the returned element should be added can be challenging due to differing DataTemplates when using a DataTemplateSelector and when elements such as ContentPresenters are automatically generated

Doing all of these things manually almost removes the point of having templates & binding. Is there any way to update only specified items in an ItemsControl so that performance does not suffer when I need to update it? Thanks.

Developer technologies | Universal Windows Platform (UWP)

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.