2011-04-15 81 views
1

我想調整Flex 4中DropDownList控件的寬度。我可以通過編輯skinclass並將PopupAnchor的屬性「popUpWidthMatchesAnchorWidth」設置爲false來實現,但在我的應用程序中,我必須使用它動作。增加dropdownList的寬度

+0

什麼特別限制,你必須使用只有DropDownList的ActionScript?爲什麼不能用'setStyle()'方法應用皮膚?請向我們提供有關您的項目的更多詳細信息,或者使用一些代碼片段來了解您的問題。 – Constantiner 2011-04-15 12:18:42

+0

我無法通過setStyle()訪問「popUpWidthMatchesAnchorWidth」屬性,我給出了答案。請驗證併發布您的評論。非常感謝Constantiner !! – vengatesh 2011-04-18 08:44:03

回答

1

非常感謝所有的反應。在這裏我給出了用於裁剪下拉寬度的代碼。

包 { import spark.components.DropDownList; import mx.controls.Alert; import spark.components.PopUpAnchor; import mx.collections.IList; import 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; 
    } 
} 

}

2

您可以將DropDownListtypicalItem屬性設置爲當前選定的項目。

Flex Examples

<?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> 
+0

非常感謝Jason,我已經從你的代碼中學到了一個新概念。但是如果我必須編寫自定義組件,並且我給出了答案 – vengatesh 2011-04-18 08:38:15

0

你還不如創建另一個皮膚爲DropDownList組件和popUpWidthMatchesAnchorWidth屬性設置爲falsePopUpAnchor皮膚部分:

<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" > 
+0

是的,這也不錯,但是在我的項目中,應該使用皮膚。所以只有我通過actionscript本身訪問了皮膚部分。 – vengatesh 2012-02-06 05:02:46