Flex 4:将 ArrayCollection 外观为列表的 ItemRenderer 的数据提供者
目标:我想将皮肤传递给列表的 itemRenderer(这是一个按钮),并且能够为该列表中的每个按钮设置皮肤。
这就是我所拥有的:
列表:
<s:List itemRenderer="renderers.ItemRenderer" dataProvider="{collectionWorkspace}" />
ArrayCollection:
<s:ArrayCollection id="collectionWorkspace">
<comp:Layout1 />
<comp:Layout2 />
<comp:Layout3 />
<comp:Layout4 />
<comp:Layout5 />
</s:ArrayCollection>
布局是带有 HostComponent 按钮的外观类。
ItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:states>
<s:State name="normal" />
</s:states>
<s:Button skinClass="{data}"/>
</s:ItemRenderer>
我收到错误(已修复以供澄清): 错误:应用程序皮肤...找不到 Button1。
Objective: I would like to pass Skins to an itemRenderer (which is a Button) of a List, and be able to skin every button in that List.
This is what I have:
List:
<s:List itemRenderer="renderers.ItemRenderer" dataProvider="{collectionWorkspace}" />
ArrayCollection:
<s:ArrayCollection id="collectionWorkspace">
<comp:Layout1 />
<comp:Layout2 />
<comp:Layout3 />
<comp:Layout4 />
<comp:Layout5 />
</s:ArrayCollection>
The Layouts are Skin classes with HostComponent Button.
ItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:states>
<s:State name="normal" />
</s:states>
<s:Button skinClass="{data}"/>
</s:ItemRenderer>
I get an error (fixed for clarification):
Error: Skin for Application....Button1 cannot be found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在向
skinClass
属性传递外观类的实例,而不是实际的类(按钮需要创建自己的外观类实例)。如果可以的话,最好的办法是使
collectionWorkspace
成为Class对象的数组,而不是实例的数组。如果您做不到这一点,您应该能够提取实例的类并将其传递给
skinClass
。编辑:
默认情况下,绑定不起作用,因为
data
在使用类初始化之前以null
开头。如果你给它null
,你会得到异常。要修复此问题,您需要返回null
和 value 之间的默认时间:我尝试使用一些按钮外观通过
ArrayCollection
执行此操作。它起作用了。You are handing the
skinClass
property an instance of the skin class, not the actual class (which the button needs to create its own instance of the skin class).If you can, the best thing to do would be to make
collectionWorkspace
be an array of Class objects, not of instances.If you can't do that, you should be able to pull out the class of the instance and pass it to the
skinClass
.EDIT:
The binding by default won't work because
data
starts off asnull
before it gets initialized with the class. If you give itnull
, you will get the exception. To fix it, you will need to return the default for the time betweennull
and value:I tried doing this with an
ArrayCollection
using some button skins. It worked.