Let's say I have 10000 WPF controls that are quite heavily styled, and that their styles are about 90% identical.
I'm wondering: what would be the best way to do, performance-wise?
- have 10000 unique styles
- have 1 style that contains the common 90% + 10000 styles inheriting this style and adding the remaining 10%
I had gone for the second option without second thoughts (on readability considerations), but I made some basic tests that tended to show this was a very bad idea in terms of performance. So are my tests buggy, or does Style-inheritance really lower perfs?
edit: okay, I was almost certain that this was not explained well enough. I'll try to detail a bit:
basically, My concern lays with the DataGrid. My cells are heavily customisable (basically, you can change every style property in a cell), and as the datagrid does not allow this to be done easily (thanks to the datagridcell's datacontext being the rowView instead of the CellView), I have done something really ugly to achieve what I add to do (see there if you want the detail). It basically consists in setting the CellStyle in code-behind for each cell.
as those styles have a lot in common, I tried setting up a common style, put in my app's static resources and base all my cell styles on this common style. (this style hosted event listeners, amongst other things, while the cellStyles added the bindings to properties such as the foreground Color, FontSize, etc...)
I noticed a big drop in the datagrid's perf when I tried that. Now, as I was not really testing this side of the app at the time, it might just have been that some part of the code was simply badly written and the drop in the perf had nothing to do with me using "basedon" styles. Anyway, I rolledBack and finished the testing I had going on.
Now, I'm tidying my code and I though about this again. Before going to te trouble of changing all my style-structure again, if anly just for test-purposes, I thought I'd ask here first if it was worth the trouble... nothing more going on...
thanks for your help!