سؤال

I have a WPF DataGrid that must have the row headers and columns added programmatically. I've implemented this successfully but the performance is not acceptable. Each time a column is added the ColumnCollection puts out a CollectionChangedEvent. I have not found a way to disable this event so I've investigated other ways of improving performance.

I have created the DataGrid on a background thread and attempted to add the grid to the UI, without success, getting the following message:

"UI Element is owned by a different thread" 

I've created the DataGrid on the main UI thread and tried to add the columns in a background thread. Same issue. I cannot ask the UI thread to do it as that's the problem in the first place.

What other approaches are used to add a lot of columns to a DataGrid? (in one case 10,000 columns)

Janene

هل كانت مفيدة؟

المحلول

I ended up using this line of code to create the DataGrid in the Background and add it to the UI.

 this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new UpdateNodesDelegate(UpdateNodes));

Got this solution from the book WPF Recipes in C# 2008.

Janene

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top