在 Flex 中创建可扩展自定义容器的最简单方法是什么?
我想创建一个 MXML 容器组件,它有一些自己的镶边(标准查询显示等),并且支持向其中添加子组件。很像现有的 mx:Panel 类,其中包含标题标签,但在添加子项方面就像普通的 mx:Box 一样。
做到这一点最简单的方法是什么?
编辑:
需要明确的是,我希望能够使用 MXML 扩展容器,因此“多个视觉子级”问题是相关的。
I want to create an MXML container component that has some of its own chrome -- a standard query display, et al -- and that supports the addition of child components to it. Something a lot like the existing mx:Panel class, which includes a title label, but acts like a plain mx:Box with regards to adding children.
What's the easiest way to do this?
Edit:
To be clear, I want to be able to extend the container using MXML, so the "Multiple visual children" problem is relevant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
扩展容器并添加标题标签。可能
可以在这里工作。将 title 设为公共 var,并为标签的 styleName 包含一个 var。然后重写
addChild()
方法,以便将添加的任何子项添加到您的容器中。当您放置 Box 元素时,为标题留出足够的空间(即,为其 y 属性提供足够的空间。如果没有标题,您可能需要回收该空间。
这是基础知识。根据您的喜好进行定制。
编辑添加:I首先创建一个 ActionScript 类,扩展我要定位的容器,然后添加“家具”——该类将始终使用的项目,例如您案例中的标题——通过覆盖
createChildren
并调用super.addChild(item)
从那时起,即使在 MXML 标记中,调用addChild
也会将项目添加到内部容器中。Extend a container and add a title label. Probably the
<mx:Canvas/>
will work here. Make the title a public var and include a var for the styleName of the label.Then override the
addChild()
method so that any child that is added is added instead to the that is your container.Leave enough space for your title when you position your Box element (i.e., give its y property enough space. If there is no title you may want to reclaim that space.
That's the basics. Customize to your heart's content.
EDITED TO ADD: I do this creating an ActionScript class first, extending the container I am targeting, and I add the "furniture" — items the class will always use, like title in your case — by overriding
createChildren
and callingsuper.addChild(item)
for those items. CallingaddChild
from then on, even in MXML markup, adds items to the inner container.我们与各州一起这样做。
我们将基础容器的镶边置于某种状态(在 mx:AddChild 元素中),然后在创建控件时使用初始化事件切换到该状态。然后将所有铬添加到容器中。
这就解决了儿童多组视觉问题。
此方法的缺点是:
编辑基础的后代时看不到镶边。
您不能直接从后代组件访问父级 chrome 控件,因为它们在编译时不存在(相反,您需要在后代可以访问的基础上定义属性、方法或事件)
但是,它对我们来说效果很好。
We do this with states.
We put the chrome for the base container in a state (in mx:AddChild elements) and then use the initialize event to switch to that state when the control is created. All the chrome is then added to the container.
That gets round the multiple sets of visual children problem.
The downsides to this approach are:
You don't see the chrome when editing descendents of the base.
You can't directly access the parent chrome controls from descendent components as they are not there at compile time (instead, you need to define properties, methods or events on the base that the descendents can access)
However, it works well for us.