Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: What is the generic container control?

Tags:

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?

like image 416
Jonathan Allen Avatar asked Jan 25 '10 01:01

Jonathan Allen


People also ask

What is container 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.

What is the difference between StackPanel and DockPanel?

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.

What is generic XAML?

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.

How can I find WPF controls by name?

FindName method of FrameworkElement class is used to find elements or controls by their Name properties.


1 Answers

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.

like image 89
John Bowen Avatar answered Sep 22 '22 13:09

John Bowen