Sorry, I'm not interested in improving performance of application which creates 600 controls. Why? Nobody will look at more than ten (to many two tens) active controls at a time. If you insist on so many controls, you'll have to explain the purpose, because this thing would be way too exotic.
So, if you're ready to re-design into more reasonable/practical approach, here is what you can do:
You need to structure design of you mass of controls into some "chapters", "sub-chapters"... into some hierarchy of reasonable depth. Each chapter goes in separate panel, but you should not ever create all 666 ;) controls. Only one chapter should be visible at a time, each containing limited observable an usable number of controls. You need only one panel, but controls are removed and re-populated each time you navigate (see below) to a chapter of interest.
How to navigate? On your main window left, imagine a control that behaves like Table of Contents (TOC). Most general view would provide a
TreeView
, a simple one (1-level hierarchy) -- a list box. On this control, you navigate from item to item each representing a chapter. Setup event handler
OnSelectionChanged
: it should clean the panel on your right and repopulate it with new set of controls.
What to put in tree view?
You need something that would be represented as a string, at the same time the item type should carry data on control set on your right. The way to resolve this is some structure with overridden
object.ToString
:
struct ItemInfo {
internal ItemInfo(string name ) { Name = name; }
public override string ToString() {
return Name.ToString();
}
string Name;
}
Now, you need to populate your TOC control with items of the type
ItemInfo
:
string name =
ItemInfo info = new ItemInfo(name);
box.Items.Add(info);
When you handle
OnSelectionChanged
, you know that you can downcast you item's
Content
to
ItemInfo
.
Develop population procedure like
CreatePageControls(ref ItemInfo info)
and call it from your handler of
OnSelectionChanged
.
Now, as you show only few controls at a time, any performance will be sufficient (on UI event, one millisecond does not count).
To give you an idea of another look at this: are you familiar with virtual container controls and/or virtual mode of controls such as grid views or list views? You can think of the design I describe as of a virtual-mode container. Alternatively, you can make more general solution using virtual container controlled by, say, a scroll bar. A scroll bar can show 900 thousands of virtual items, with only a small part of them existing physically at the same time: only those in the visible part of scrollable area plus as many down and up of this place, for better cashing.
How about that?