Flex中如何通过variableRowHeight属性调整PopUpButton控件下拉菜单分隔符间隔的例子

By Minidxer | October 4, 2008

接下来的例子演示了Flex中如何通过variableRowHeight属性,调整PopUpButton控件下拉菜单分隔符间隔。

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


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

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application name="PopUpButton_popUp_dataProvider_type_test_2"
  3.         xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="top"
  6.         backgroundColor="white">
  7.  
  8.     <mx:Style>
  9.         PopUpButton {
  10.             popUpStyleName: myCustomPopUpStyleName;
  11.             closeDuration: 0;
  12.             openDuration: 0;
  13.         }
  14.  
  15.         .myCustomPopUpStyleName {
  16.             fontWeight: normal;
  17.             textAlign: left;
  18.         }
  19.     </mx:Style>
  20.  
  21.     <mx:Script>
  22.         <![CDATA[
  23.             import mx.controls.Menu;
  24.  
  25.             private var menu:Menu;
  26.  
  27.             private function popUpButton_initialize():void {
  28.                 menu = new Menu();
  29.                 menu.dataProvider = arr;
  30.                 menu.variableRowHeight = checkBox.selected;
  31.                 popUpButton.popUp = menu;
  32.                 popUpButton.open();
  33.             }
  34.  
  35.             private function checkBox_change(evt:Event):void {
  36.                 menu.variableRowHeight = checkBox.selected;
  37.                 menu.invalidateSize();
  38.                 popUpButton.open();
  39.             }
  40.         ]]>
  41.     </mx:Script>
  42.  
  43.     <mx:Array id="arr">
  44.         <mx:Object label="One" />
  45.         <mx:Object label="Two" />
  46.         <mx:Object label="Three" />
  47.         <mx:Object type="separator" />
  48.         <mx:Object label="The quick brown fox jumped over the lazy dog." />
  49.     </mx:Array>
  50.  
  51.     <mx:ApplicationControlBar dock="true">
  52.         <mx:CheckBox id="checkBox"
  53.                 label="variableRowHeight:"
  54.                 labelPlacement="left"
  55.                 selected="true"
  56.                 change="checkBox_change(event);" />
  57.     </mx:ApplicationControlBar>
  58.  
  59.     <mx:PopUpButton id="popUpButton"
  60.             label="PopUpButton with separator"
  61.             openAlways="true"
  62.             initialize="popUpButton_initialize();" />
  63.  
  64. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Flex | Tags: , , ,

Search Posts

Archives

Sponsored Ads