Hi,
In my scenario i do not want virtualization on and hence I have switched it off by wrapping grid in scrollviewer, the performance is good when i am scrolling but the moment I add conditional formatting (via code behind) i see the scrolling is very slow. I used JetBrains dotTrace and windbg and can see the grid is recycling cells (See attached symbol). Can you please explain why this is so, the reason i turned off virtualization is because i have limited number of data rows (around 2000) and i do not want virtualization enabled.
similarly when i update the underlying data property, i see the below function slows down the UI phenomenally. As i mentioned there is no virtualization, the view port is very small, around 2000 rows and only 30 rows are visible with 10 columns. The performance etc is great when conditional formatting is not enabled, it works like a charm, but the moment i enable conditional formatting the whole grid struggles.
I see in the below stack trace, it is compiling dynamic delegate which is slowing down, is there any work around to improve the performance. The reason we choose xamgrid was because we expected performance would be better but this is not the case.
Appreciate your help.
THanks,
Rohit
Hello Rohit,
I have been looking into your issue and when enabling conditional formatting in the XamGrid positioned in a ScrollViewer, the scrolling works fine on my side. I am attaching a sample application() that I used for my tests. Could you please try the sample on your side and modify it if needed ? Also could you please tell me the version of our assembly files that you use like 11.2.20112.2316
Looking forward to hearing from you.
I have made a sample for you/developers.
In this app, all the grids are hosted inside xamtab and virtualization is off
To reproduce the issue:
1 - Compile and run the attach code
2 - Click on Tab 3, this will take a few seconds to render as virtualization is off, once the cells are rendered you can scroll and see the scrolling is very smooth, no issues here
3 - Next click on "Add Conditional Formatting" button, give it some time to render condition format, again scroll and see the performance is very good indeed, there is no lag.
4 - Finally click on "Add 1000 items" button, this will add a new row to the collection every 500 ms, now try to scroll and you'd see the grid literally freezes and scrolling is very jagged.
... Now repeat the same steps without "clicking on Add Conditional Formatting" i.e. step #3. When adding row every 500ms the CPU usage is within in limits and the grid scrolls not too bad, but if we add conditional formatting the performance is horrible.
Further if the grid has more column and you try to scroll horizontally you can see that the grid flickers i.e. all cells are removed, the grid is blanked out and then suddenly it reappears.
Thanks,Rohit
As to your other question, i am using the latest release i.e. 12.2.2236
I have contacted our development team about more information on this matter and they will do the best to modify the reported behavior for our upcoming Service Release.
Thank you for understanding.
>> If the ‘ShouldRefreshOnDataChange’ property is set to “true”, it makes the rule to be reapplied if the data is changed and this makes the delay in your scenario.
I am sorry but i think this is pretty obvious from the sample that i created, there is nothing new you are telling me here.
I cannot go and explain this to my business users (around 150+ around the globe) that as vendor library repaints all the cells + spikes CPU, we cannot refresh the cells, it is better if i hand over my resignation letter to them. I cannot explain but believe me conditional formatting is very important in my scenarios so cells could stand out.
I used xamgrid as it was developed for performance out of the box, and if i cannot apply a style to a new row without spiking up cpu then xamgrid is of no use to me.
I very well comprehend and understand that this is a limitation and not currently supported, all i am asking for is to know how long would it take to get it fixed so that if needed i can swtich to other vendors. So my question is to know if the developement team is anytime going to work on this or should i evaluate other vendors? personally this is a basic feature and i cannot push you enough to have it, appreciate honest comments.
Thanks so much,
Hello,
As is obivous from my sample I can understand that xamgrid refreshes all cells. The added row sample was just to show you that CPU spikes up when a new row is added. This is not the production code.
In my case the style is not only applied just when the row is added/initialized (this was just a sample to show that xamgrid refreshes all cells) but when some calculation is done on the particular row cell value which causes other cell value to change and that is when i want the style to be applied on that cell and or rows, apparently I have around 4 columns and depending on the state machine each such cell shows a different background color (gradient color depending on some financial calculation)(, I cannot put if and buts code every where in my code just so i could apply styling, best would be if i could define style and get it applied appropriately without spiking up the cpu.
Would it be possible to patch the performance issue in the next service release? or by creating a new refresh methodology?
Thanks
The conditional formatting rules are applied over a column either by a row (i.e. the whole column layout) or a cell (i.e. only the column cells). Setting ShouldRefreshOnDataChange to true means that the rule(s) will be reapplyed over the column layout cells after changing the data source. You could achieve styling only the added row by handling the CollectionChanged event of the data source of the grid and applying the desired style to the new row. Here is a sample code:bool isInitialized = false;public MainWindow(){ ..... Source = new ObservableCollection<Data>(); this.Source.CollectionChanged += Source_CollectionChanged; Source.Add(....) isInitialized = true; }void Source_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e){ if (isInitialized && e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { Style s = new System.Windows.Style(); s.Setters.Add(new Setter() { Property = CellControl.BackgroundProperty, Value = new SolidColorBrush(Colors.Yellow) }); Grid1.Rows[Grid1.Rows.Count - 1].CellStyle = s; }}Note that the grid property IsAlternateRowsEnabled should be "False" so the added style could be applied to every row.
I have logged this behavior with our developers in our tracking system, with an issue ID of 152229. I have also created a support ticket on your behalf with number CAS-122402-N5N4Q0 in order to link the development issue to it so that you are automatically updated when a Service Release containing your fix is available for download.