WPF:什么是通用容器控件?

发布于 2024-08-19 09:20:21 字数 133 浏览 7 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦言归人 2024-08-26 09:20:21

我认为最接近您正在寻找的东西是 ContentControl。它没有自己的布局,也没有默认的 UI(除非您将其模板化以执行其中一项或两项操作),但可以采用任何对象作为其 Content 属性(WPF UIElement 或其他)并提供任何CLR 对象的 UI,通过分配给其 ContentTemplate 属性的 DataTemplate 实现。在这方面,它提供了一个注入其他内容(如 HTML 中的 div)的好地方。它也恰好是许多标准内置控件的基类:ButtonListBoxItemUserControlWindow< /代码>。

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'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.

酷到爆炸 2024-08-26 09:20:21

一些更常用的容器是:

Grid
StackPanel
DockPanel
WrapPanel
Canvas

另请参阅 MSDN 面板概述

Some of the more commonly used containers are:

Grid
StackPanel
DockPanel
WrapPanel
Canvas

See also MSDN Panels Overview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文