Flex中如何通过arrowButtonWidth样式自定义PopUpButton按钮宽度的例子

By Minidxer | March 12, 2009

接下来的例子演示了Flex中如何通过arrowButtonWidth样式,自定义PopUpButton按钮宽度。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="top"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Style>
  8.         PopUpButton {
  9.             popUpStyleName: myCustomPopUpStyleName;
  10.         }
  11.  
  12.         .myCustomPopUpStyleName {
  13.             fontWeight: normal;
  14.             textAlign: left;
  15.         }
  16.     </mx:Style>
  17.  
  18.     <mx:Script>
  19.         <![CDATA[
  20.             import mx.controls.Menu;
  21.  
  22.             private var menu:Menu;
  23.  
  24.             private function init():void {
  25.                 menu = new Menu();
  26.                 menu.labelField = "@label";
  27.                 menu.dataProvider = xmlList;
  28.                 popUpButton.popUp = menu;
  29.                 menu.maxWidth = popUpButton.width;
  30.             }
  31.         ]]>
  32.     </mx:Script>
  33.  
  34.     <mx:XMLList id="xmlList">
  35.         <node label="Alert" />
  36.         <node label="Button" />
  37.         <node label="ButtonBar" />
  38.         <node label="CheckBox" />
  39.         <node label="ColorPicker" />
  40.         <node label="ComboBox" />
  41.     </mx:XMLList>
  42.  
  43.     <mx:ApplicationControlBar dock="true">
  44.         <mx:Form styleName="plain">
  45.             <mx:FormItem label="arrowButtonWidth:">
  46.                 <mx:HSlider id="slider"
  47.                         minimum="16"
  48.                         maximum="64"
  49.                         value="16"
  50.                         snapInterval="1"
  51.                         tickInterval="4"
  52.                         showTrackHighlight="true"
  53.                         liveDragging="true" />
  54.             </mx:FormItem>
  55.         </mx:Form>
  56.     </mx:ApplicationControlBar>
  57.  
  58.     <mx:PopUpButton id="popUpButton"
  59.             label="Please select an item..."
  60.             openAlways="true"
  61.             arrowButtonWidth="{slider.value}"
  62.             creationComplete="init();" />
  63.  
  64. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: PopUpButton | No Comments » | 398 views Tags: ,

Search Posts