views:

19

answers:

1

Hi

I have a WPF Grid and a list of values. The list of values have a row and column property and the content value. There are between 200 and 14,000 values to be displayed in a formatted grid.

I have added rows and columns to the grid then added text blocks to the grid in the correct row/column positions.

This works great till I have around 8,000 values then it slows down. To remedy I put it out to a thread to perform the layout, problem is, my TextBlocks are created on one thread then when I try to add them to the Children member of the Grid using the UI dispatcher the text block is on a different thread.

So the question is, can I switch the thread affinity of the Textblocks to the UI thread after I've created them?

Thanks Owen

+1  A: 

Are you going to show all the 8000 values at once or are you having some scrollbars?

Adding 8000 controls to a view would be considered a bad design.

Why don't you go for a ListView and template it according your design if the values have the same template? So that you can bind it to an ObservableCollection which could be filled up using the List of Values you have. The fill could be made asynchronous using Dispatcher's BeginInvoke method

Veer
Veer, thanks for your help. The problem I had with ListView was getting the columns to line up on each row. It is most likely an error or misunderstanding on my part. As it happened, you gave me an idea... I've not loaded the first 200 "cells" of data onto the page on the UI thread then done the remainder using Dispatchers begin Invoke. This has given me the data i need almost immediately and strangely the remaining items fill in a lot quicker too.Thanks for your help
Owen79