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.
Hello,
Any updates on the issue? Did you try my last example?
Hi Rohit,
I have been looking into your concerns and if the ‘ShouldRefreshOnDataChange’ property is set to “True” makes the corresponding conditional formatting to be reapplied on all the cells, not only on the last modified. This is the design behavior of the control.
Let me know, if you need any further assistance on this matter.
I am sorry, but as per the documentation this is to be applied per row not "rows" across the grid.
So you are saying - If i have 2000 rows on my grid and row level conditional formatting is applied, and I add one row, we are going to repaint all rows/cells across the grid? If i am adding one row why are other row's cell style is being re-applied? Seriously, does it sound right to you? Because of this the entire core is maxed out when i add just one row.
Could you please double check this behavior with your development team. This sounds more like a design issue/bug to me rather "by design" behavior.
Alternatively: how can i apply row level conditional formatting to the newly added row to the grid (without repainting all the cells)?
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.
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