views:

102

answers:

2

Hi guys!

I'm using WPF and C#.

I have a problem. I need to create a lot of bindable templated controls in scrollable area (they are all of different types). For example 1000 textboxes, 1000 drop down lists, and 1000 checkboxes.

The problem is that when they are all created it works really slow.

The question is - whether it is possible to have so many controls simultaniously without lags and in what direction should I search for the solution? I'd like to save an ability to use Templates, Databinding and simple event handling like mouse clicking.

P.S. I tried lot's of things (rendering of geometry only, different base classes and so on) but currently the only approach that seems working for me (i haven't tried it yet) is to create only those controls that fit into the current viewport and update this list of controls on scrolling.

P.P.S I know that there is a mechanism in 3.5 SP1 that is used in ListBox when list items are reused during scrolling but such approach cannot be used here because all those items are of different types.

Thank's a lot.

+1  A: 

First - I'd question the rationale in design of this type of requirement. Having thousands of controls in anything except a grid or list of some sort (where they are all constant, not changing, so the list-style approach would work fine) is going to be incredibly confusing to your user. You're basically forcing a non-obvious, changing interface with thousands of items at them.

That being said...

P.P.S I know that there is a mechanism in 3.5 SP1 that is used in ListBox when list items are reused during scrolling but such approach cannot be used here because all those items are of different types.

This actually is probably your best approach. This should work fine - although it won't be as simple as the list box mechanism. You can always pre-create the controls - just create enough of each type of control as required to fill the current container, and as you scroll, reassign the appropriate controls into the appropriate locations.

If you truly need thousands of controls, this will most likely be your best option.

Reed Copsey
I've been told and have seen for myself that a smaller number of controls with a larger number of databindings outperforms the other way around. FrameworkUIElement's are *very* expensive.
sixlettervariables
@sixlettervariables: That's what I was saying here - It'd be better to have a smaller number of total controls, and reassign (reuse) the databindings while scrolling, the same way a list box does. He'd just need to additionally reposition/layout during scroll.
Reed Copsey
The problem is that there are a lot of types of that controls. I've mentioned textboxes and some other primitives just to make it easier to understand the problem.Actually there will be controls containing several textboxes, graphic primitives, animation etc.If i'll use approach with reuse i'll need to create some set of basic control types, I suppose.
Dmitry Estenkov
+2  A: 

The fact that you want ~3000 controls on a single screen is a problem and it is usually a sign that you are approaching you GUI from the wrong angle. I am not very experienced with WPF, but my WinForms knowledge tells me that 1000+ control instances is just asking for trouble. This is what ListBoxes, DataGrids, and other tabular/list format controls were designed for.

I gave a similar answer to a similar problem here: Super Slow C# Custom Control

Maybe if you explain what are you trying to do instead of what solution you are trying to implement someone here can push you in the right direction.

Matthew Ruston
Actually I need to create some kind of dinamically updated schemas.With a lot of items with different animation and/or visualisation depending of their inner state.Imagine for example presentation of power plant with transformators generators etc. with a lot of parameters to show and/or edit.
Dmitry Estenkov