微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flex组合框中显示项目的自定义项目渲染器

我在组合框中使用自定义项呈示器来显示自定义图形而不是认文本标签.

这适用于下拉列表,但显示的项目(当列表关闭时)仍然是我的对象的文本表示.

有没有办法让显示的项目呈现与下拉列表中的项目相同的方式?

解决方法

认情况下,您无法执行此操作.但是,如果扩展ComboBox,则可以轻松添加功能.这是一个简单的例子,它是一个粗略的版本,可能需要测试/调整,但它显示了如何实现这一目标.
package
{
    import mx.controls.ComboBox;
    import mx.core.UIComponent;

    public class ComboBox2 extends ComboBox
    {
        public function ComboBox2()
        {
            super();
        }

        protected var textInputReplacement:UIComponent;

        override protected function createChildren():void {
            super.createChildren();

            if ( !textInputReplacement ) {
                if ( itemRenderer != null ) {
                    //remove the default textInput
                    removeChild(textInput);

                    //create a new itemRenderer to use in place of the text input
                    textInputReplacement = itemRenderer.newInstance();
                    addChild(textInputReplacement);
                }
            }
        }

        override protected function updatedisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updatedisplayList(unscaledWidth,unscaledHeight);

            if ( textInputReplacement ) {
                textInputReplacement.width = unscaledWidth;
                textInputReplacement.height = unscaledHeight;
            }
        }
    }
}

原文地址:https://www.jb51.cc/flex/174277.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐