Spark 的最佳方法通常是皮肤。
通过属性进行基本控制,例如更改所选颜色:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:DataGrid selectionColor="0xff0000">
<s:dataProvider>
<s:ArrayList>
<fx:String>a</fx:String>
<fx:String>b</fx:String>
<fx:String>c</fx:String>
</s:ArrayList>
</s:dataProvider>
</s:DataGrid>
</s:Application>
要为 GridColumn 实现项目渲染器,请使用States
定义选定状态的显示方式
GridColumnItemRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
clipAndEnableScrolling="true">
<s:states>
<s:State name="normal" />
<s:State name="selected" />
</s:states>
<fx:Script>
<![CDATA[
override public function prepare(hasBeenRecycled:Boolean):void
{
lblData.text = data[column.dataField]
}
]]>
</fx:Script>
<s:Label id="lblData"
color.selected="0x00ff00"
top="9"
left="7" />
</s:GridItemRenderer>
数据网格
上面的项目渲染器是从 Spark GridColumn 指定的,如下所示:
<s:DataGrid>
<s:columns>
<s:ArrayList>
<s:GridColumn itemRenderer="GridColumnItemRenderer" />
</s:ArrayList>
</s:columns>
</s:DataGrid>