创建组合框与非选择性分离 [英] Create combobox with non selectable separator

查看:143
本文介绍了创建组合框与非选择性分离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义组合框。 事实上,我喜欢创造了两个阵列COMBOX通过这样的线分开。

I'd like to custom combobox. Indeed, I like to create a combox with two array separate by a line like that.

所有的以上40行必须无可选择的。

The line between All and above 40 must no selectable.

你知道该怎么做?

感谢您帮助

推荐答案

比方说,我们有这样一个模型组合框:

Let's say we have a ComboBox with a model like this:

<s:ComboBox>
    <s:ArrayList>
        <fx:String>A</fx:String>
        <fx:Object />
        <fx:String>B</fx:String>
    </s:ArrayList>
</s:ComboBox>

的字符串是我们的常规元素和对象再presents的分隔符。我简化了的东西在这里,但你应该能够把这种以您的具体情况。

The Strings are our regular elements and the Object represents the separator. I'm simplifying things here, but you should be able to translate this to your specific situation.

现在我们要为不同的ItemRenderer分配给每个类型的元素。我们可以通过 itemRendererFunction 属性的方式做到这一点。

Now we want to assign a different ItemRenderer to each type of element. We can do this by means of the itemRendererFunction property.

<s:ComboBox itemRendererFunction="getItemRenderer">

private function getItemRenderer(item:*):IFactory {
    var renderer:Class = item is String ? DefaultItemRenderer : SeparatorItemRenderer
    return new ClassFactory(renderer);
}

现在,让我们创建一个 SeparatorItemRenderer ,将只包含一条水平线,将有它的启用属性设置为。这最后一部分是非常重要的,因为它会使该项目不可选的。

Now lets create that SeparatorItemRenderer which will contain just a horizontal line and will have its enabled property set to false. This last part is very important because it will make the item non-selectable.

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                autoDrawBackground="false" enabled="false"
                height="10" disabledAlpha="1">

    <s:Line left="0" right="0" verticalCenter="0">
        <s:stroke>
            <s:SolidColorStroke color="0xdddddd" />
        </s:stroke>
    </s:Line>

</s:ItemRenderer>

和应该这样做。

这篇关于创建组合框与非选择性分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆