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?
WPF supports a rich set of control containers derived from the base Panel class. These include Canvas, DockPanel, StackPanel, WrapPanel, and Grid. Silverlight is a little more restricted, owing to its need to keep the runtime install as light as possible, and supports only Canvas, Grid, and StackPanel.
For example, the order of child elements can affect their size in a DockPanel but not in a StackPanel. This is because StackPanel measures in the direction of stacking at PositiveInfinity, whereas DockPanel measures only the available size. The following example demonstrates this key difference.
xaml. If the style is not found in the theme dictionary, it looks in Generic. xaml i.e for controls whose look doesn't depend on the theme. This only applies to any custom controls you have defined i.e. classes derived from Control, directly or indirectly.
FindName method of FrameworkElement class is used to find elements or controls by their Name properties.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With