开发者

WPF: What is the generic container control?

开发者 https://www.devze.com 2022-12-18 10:57 出处:网络
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.

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?


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.


Some of the more commonly used containers are:

Grid
StackPanel
DockPanel
WrapPanel
Canvas

See also MSDN Panels Overview.

0

精彩评论

暂无评论...
验证码 换一张
取 消