0

This is a kind of non-objective question, since I think that the mileage may vary, but, given a scenario where I can use a Control Template (declared at the Resources section of my Page) or a UserControl, which would result in the best performance?

The reason for asking is that I've just had a performance issue with WPF (trying to create a table -- grid -- with as many as 5000 controls) and one thing that I did in order to improve the performance of the page was converting one control template (which represented one row within the grid) to a UserControl, which I suspected would bring better perfomance. But after profiling the code, I've found out that I actually lost performance -- not much, but enough for me to go back to the old code.

Anyone has any insight on the matter?

Bruno Brant
  • 8,226
  • 7
  • 45
  • 90

1 Answers1

3

For your question I don't have a good answer. However having a grid with 5000 controls sounds scaring. I would try to use a virtualizing-technology such as VirtualizingStackPanel, so that your controls will be recycled and only created if necessary (if possible).

Maybe this post gives you an idea.

Community
  • 1
  • 1
HCL
  • 36,053
  • 27
  • 163
  • 213
  • Additionally when you use Recycling option it will be keeping only visible number of containers. MSDN description http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizationmode.aspx – bartosz.lipinski Feb 17 '11 at 08:22
  • Well, that should probably have been my first question. I didn't expected the user to create such a scenario -- I thought at most 500 lines, which would be a lot already. – Bruno Brant Feb 18 '11 at 00:15