문제

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