Flex组合框中显示项目的自定义项目渲染器
发布时间:2020-12-15 02:14:18 所属栏目:百科 来源:网络整理
导读:我在组合框中使用自定义项呈示器来显示自定义图形而不是默认文本标签. 这适用于下拉列表,但显示的项目(当列表关闭时)仍然是我的对象的文本表示. 有没有办法让显示的项目呈现与下拉列表中的项目相同的方式? 解决方法 默认情况下,您无法执行此操作.但是,如果
我在组合框中使用自定义项呈示器来显示自定义图形而不是默认文本标签.
这适用于下拉列表,但显示的项目(当列表关闭时)仍然是我的对象的文本表示. 有没有办法让显示的项目呈现与下拉列表中的项目相同的方式? 解决方法
默认情况下,您无法执行此操作.但是,如果扩展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; } } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |