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

由网友(难以启齿的痛)分享简介:我使用的是自定义项目渲染在组合框中显示自定义绘制默认的文本标签,而不是I am using a custom item renderer in a combobox to display a custom drawing instead of the default text label.这工作正常的下拉列表中,但...

我使用的是自定义项目渲染在组合框中显示自定义绘制默认的文本标签,而不是

I am using a custom item renderer in a combobox to display a custom drawing instead of the default text label.

这工作正常的下拉列表中,但所显示的项目(当列表被关闭)仍然是我对象的文本再presentation。

This works fine for the dropdown list but the displayed item ( when the list is closed) is still the textual representation of my object.

有没有办法让显示的项目呈现同样的方式对视了一眼,在下拉列表?

Is there a way to have the displayed item rendered the same way as the one in the dropdown?

推荐答案

在默认情况下,你不能做到这一点。但是,如果你扩展组合框,你可以轻松地添加此功能。下面是一个简单的例子,这是一个粗略的版本,可能需要测试/调整,但它展示了如何做到这一点。

By default you cannot do this. However, if you extend ComboBox you can add this functionality easily. Here is a quick example, it is a rough version and probably needs testing / tweaking but it shows how you could accomplish this.

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;
    		}
    	}
    }
}
阅读全文

相关推荐

最新文章