Flex组合框中显示项目的自定义项呈示器 [英] Flex custom item renderer for the displayed item in the combobox
问题描述
我在组合框中使用自定义项呈示器来显示自定义图形而不是默认文本标签。
I am using a custom item renderer in a combobox to display a custom drawing instead of the default text label.
这对下拉列表很好,但显示项目(当列表关闭时)仍然是我的对象的文本表示。
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?
推荐答案
默认情况下不能这样做。但是,如果您扩展ComboBox,您可以轻松添加此功能。这是一个简单的例子,它是一个粗糙的版本,可能需要测试/调整,但它显示了如何可以实现这一点。
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;
}
}
}
}
这篇关于Flex组合框中显示项目的自定义项呈示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!