views:

25

answers:

1

I need to write a control that is supposed to take only a certain type of child controls. Functionally it works like a Selector in that I can select/activate on of its childs but it seems that I can not derive from Selector because an ItemsControl can take any type of child (object). I really would like to have compiletime typesafety here. So throwing an exception when a child of the wrong type is added is not an option.

This constraint seems to be necessary because the parent control needs to rely on certain properties and behavoir in its children. There is also some direct communication of the children with its parents.

How is something like this usually handled in WPF.

+1  A: 

ItemsControl's wrap their children in an item container type of your choice. Thus, you know the children of your ItemsControl will always be of that type. For example, ListBoxes always have ListBoxItems as children.

HTH,
Kent

Kent Boogaart
How do I chose the item container type for my Selector derived class?
bitbonk
According to this article: http://drwpf.com/blog/2008/07/20/itemscontrol-g-is-for-generator/ it must be GetContainerForItemOverride() ;)
bitbonk