29

In HTML the generic container control is a DIV. It doesn't do a anything on its own, but it makes for a great place to hang stuff off.

Likewise in WinForms the generic container control was the Panel. Again, this is what I would use as a place holder to later load other controls.

What should I use for WPF?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447

2 Answers2

37

I think the closest thing to what you're looking for is a ContentControl. It does no layout of its own and has no default UI (unless you template it to do one or both of those) but can take any object as it's Content property (WPF UIElement or otherwise) and provide any UI for a CLR object through a DataTemplate assigned to its ContentTemplate property. In that respect it provides a good place to inject other content (like a div in HTML). It also happens to be a base class for many of the standard built-in controls: Button, ListBoxItem, UserControl, Window.

WPF panels don't work as well for placeholders because they can't be templated or have children set through bindings, excepting cases where they are contained in other controls that handle injecting bound content, like the ItemsControl-ItemsPresenter-ItemsPanel relationship.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
John Bowen
  • 24,213
  • 4
  • 58
  • 56
21

Some of the more commonly used containers are:

Grid
StackPanel
DockPanel
WrapPanel
Canvas

See also MSDN Panels Overview.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
kenwarner
  • 28,650
  • 28
  • 130
  • 173
  • To add to this, it all depends on what you need to do with those later-loaded controls. I. e. what layout they should have, etc. In one of those cases I went with a Grid. And DockPanel is probably not that good if you need to load multiple controls. – Joey Jan 25 '10 at 01:54
  • 1
    In this case I want as few assumptions as possible. Any layout should be handled by the contol being loaded, so a single control restriction make sense. – Jonathan Allen Jan 25 '10 at 02:09
  • Not the simple answer I was expecting, but that link was a really good read. – Jonathan Allen Jan 25 '10 at 02:11
  • these do not have template. I want to have the simplest control, that has template so I can use it inside my styles (I just want to use it as an animate-able element, but does not provide other functionalities.). is `ContentControl` right choice? or is there more appropriate control for this? – M.kazem Akhgary Jan 22 '17 at 10:42
  • This does not answer the question at all. – Bretton Wade Jul 20 '19 at 16:05