WPF gotcha stackpanel.children.add

I havent blogged for a while because i've been working on integrated live tv tuning and WPF into my media player. This has not been a trivial task. Getting access to the directshow filter graph to manually build the graph is not something that WPF was designed for. More on this on a later blog.

Todays note is a problem that i have run into in dynamically constructing a large GUI in WPF. i have around about 10,000 custom controls that are added to a stackpanel. ( the custom controls each represent a tv show in a TV guide ).

Constructing and populating the custom controls is pretty quick. Adding them to the stackpanel is a problem. 10,000 controls take about 10 seconds to add. This is way to slow for my liking. My first thought was to move it into a worker thread, however because WPF is STA and adding anything to the GUI has to be done on the main thread, the way to do this isn't obvious. Once I have found a solution, I'll post it up here.

0 comments: