增加dropdownList的宽度

| 我想在flex 4中调整DropDownList控件的宽度。我可以通过编辑skinclass并将PopupAnchor的Property \“ popUpWidthMatchesAnchorWidth \”设置为false来做到这一点,但是在我的应用程序中,我必须使用actionscript来做到这一点。     
已邀请:
您可以将
DropDownList
typicalItem
属性设置为当前选定的项目。 从Flex示例中:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!-- http://blog.flexexamples.com/2010/01/21/resizing-a-spark-dropdownlist-control-to-match-the-currently-selected-item-in-flex-4/ -->
<s:Application name=\"Spark_DropDownList_typicalItem_test\"
        xmlns:fx=\"http://ns.adobe.com/mxml/2009\" 
        xmlns:s=\"library://ns.adobe.com/flex/spark\" 
        xmlns:mx=\"library://ns.adobe.com/flex/mx\">

    <s:DropDownList id=\"cb\"
                    labelField=\"name\"
                    typicalItem=\"{cb.selectedItem}\"
                    requireSelection=\"true\"
                    left=\"20\" top=\"20\">
        <s:dataProvider>
            <s:ArrayList>
                <fx:Object name=\"Baltimore Orioles\" abbr=\"BAL\" />
                <fx:Object name=\"Boston Red Sox\" abbr=\"BOS\" />
                <fx:Object name=\"Chicago White Sox\" abbr=\"CWS\" />
                <fx:Object name=\"Cleveland Indians\" abbr=\"CLE\" />
                <fx:Object name=\"Detroit Tigers\" abbr=\"DET\" />
                <fx:Object name=\"Kansas City Royals\" abbr=\"KC\" />
                <fx:Object name=\"Los Angeles Angels of Anaheim\" abbr=\"LAA\" />
                <fx:Object name=\"Minnesota Twins\" abbr=\"MIN\" />
                <fx:Object name=\"New York Yankees\" abbr=\"NYY\" />
                <fx:Object name=\"Oakland Athletics\" abbr=\"OAK\" />
                <fx:Object name=\"Seattle Mariners\" abbr=\"SEA\" />
                <fx:Object name=\"Tampa Bay Devil Rays\" abbr=\"TB\" />
                <fx:Object name=\"Texas Rangers\" abbr=\"TEX\" />
                <fx:Object name=\"Toronto Blue Jays\" abbr=\"TOR\" />
            </s:ArrayList>
        </s:dataProvider>
    </s:DropDownList>

</s:Application>
    
非常感谢所有响应者。在这里,我给出了用于剪切下拉列表宽度的代码。 包 {     导入spark.components.DropDownList;     导入mx.controls.Alert;     导入spark.components.PopUpAnchor;     导入mx.collections.IList;     导入spark.components.ComboBox;
public class customDDList extends DropDownList
{   
    [SkinPart(popUpWidthMatchesAnchorWidth)]  
    public var popUp:PopUpAnchor ; 
    public function customDDList():void
    {
        super();
    }
    override protected function partAdded(partName:String, instance:Object):void 
    {    
        super.partAdded(partName, instance);   
                     if (partName == \"popUp\")   
        {
            instance.popUpWidthMatchesAnchorWidth = false;

        }

    }
    public override function set dataProvider(value:IList):void
    {
        super.dataProvider = value;
    }
}
}     
您也可以为DropDownList组件创建另一个外观并将
PopUpAnchor
外观部分上的
popUpWidthMatchesAnchorWidth
属性设置为
false
    <s:PopUpAnchor id=\"popUp\"  
    displayPopUp.normal=\"false\" displayPopUp.open=\"true\" includeIn=\"open\"
    left=\"0\" right=\"0\" top=\"0\" bottom=\"0\" 
    itemDestructionPolicy=\"auto\" 
    popUpPosition=\"below\"
    popUpWidthMatchesAnchorWidth=\"false\" >
    

要回复问题请先登录注册