WPF:什么是通用容器控件?
在 HTML 中,通用容器控件是 DIV。它本身不会做任何事情,但它是一个挂东西的好地方。
同样,在 WinForms 中,通用容器控件是面板。同样,这就是我将用作稍后加载其他控件的占位符。
我应该为 WPF 使用什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为最接近您正在寻找的东西是
ContentControl
。它没有自己的布局,也没有默认的 UI(除非您将其模板化以执行其中一项或两项操作),但可以采用任何对象作为其Content
属性(WPF UIElement 或其他)并提供任何CLR 对象的 UI,通过分配给其ContentTemplate
属性的DataTemplate
实现。在这方面,它提供了一个注入其他内容(如 HTML 中的div
)的好地方。它也恰好是许多标准内置控件的基类:Button
、ListBoxItem
、UserControl
、Window< /代码>。
WPF 面板不适用于占位符,因为它们无法模板化或通过绑定设置子项,除非它们包含在处理注入绑定内容的其他控件中,例如
ItemsControl
-ItemsPresenter
-ItemsPanel
关系。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'sContent
property (WPF UIElement or otherwise) and provide any UI for a CLR object through aDataTemplate
assigned to itsContentTemplate
property. In that respect it provides a good place to inject other content (like adiv
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.一些更常用的容器是:
Grid
StackPanel
DockPanel
WrapPanel
Canvas
另请参阅 MSDN 面板概述。
Some of the more commonly used containers are:
Grid
StackPanel
DockPanel
WrapPanel
Canvas
See also MSDN Panels Overview.