如何在 MXAdvancedDataGridItemRenderer 中设置悬停颜色?
我正在尝试使用 MXAdvancedDataGridItemRenderer 为 AdvancedDataGrid 创建项目渲染器。
当我将示例自定义项目渲染器 (MXAdvancedDataGridItemRenderer) 附加到 AdvancedDataGrid 中的分层数据时,项目渲染器无法正确渲染单元格。 如果也未选择自定义渲染器,则仅将其渲染为悬停(突出显示)状态。当选择该行并将其悬停时,自定义项渲染器将仅渲染选定的单元格。
如何让自定义渲染器识别出在突出显示行时应该突出显示?
下图显示了一个示例。第一行被选中,鼠标悬停在第二个单元格上。正如您所看到的,单元格呈现为“选定”而不是“悬停”。
这是一个示例应用程序:
<?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"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var data:ArrayCollection = new ArrayCollection([
{label:"Fruit", children:[
{label:"Apple", price:1.5},
{label:"Banana", price:2},
{label:"Orange", price:1.75}]},
{label:"Drink", children:[
{label:"Water", price:0.5},
{label:"Milk", price:2.25},
{label:"Juice", price:1.25}]}
]);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:AdvancedDataGrid x="10" y="10" width="350" height="200" itemRenderer="TestItemRenderer">
<mx:dataProvider>
<mx:HierarchicalData source="{data}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Name" dataField="label"/>
<mx:AdvancedDataGridColumn headerText="Price" dataField="price"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Application>
这是示例 MXAdvancedDataGridItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{listData.label}" />
</s:MXAdvancedDataGridItemRenderer>
I am trying to create an item renderer for an AdvancedDataGrid, using a MXAdvancedDataGridItemRenderer.
When I attach a sample custom item renderer (MXAdvancedDataGridItemRenderer) to hierarchical data in an AdvancedDataGrid the item renderer does not render the cell correctly.
The custom renderer will only render as a hovered (highlighted) state if it also not selected. When the row is selected and hovered then the custom item renderer will only render the cell as selected.
How can I get the custom renderer to recognize that is should render highlighted when the row is highlighted?
The image below shows an example of this. The first row is selected and the mouse is over the second cell. As you can see the cell is rendered as 'selected' and not as 'hovered'.
This is an example application:
<?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"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var data:ArrayCollection = new ArrayCollection([
{label:"Fruit", children:[
{label:"Apple", price:1.5},
{label:"Banana", price:2},
{label:"Orange", price:1.75}]},
{label:"Drink", children:[
{label:"Water", price:0.5},
{label:"Milk", price:2.25},
{label:"Juice", price:1.25}]}
]);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:AdvancedDataGrid x="10" y="10" width="350" height="200" itemRenderer="TestItemRenderer">
<mx:dataProvider>
<mx:HierarchicalData source="{data}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Name" dataField="label"/>
<mx:AdvancedDataGridColumn headerText="Price" dataField="price"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Application>
And this is the example MXAdvancedDataGridItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{listData.label}" />
</s:MXAdvancedDataGridItemRenderer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想尝试将 autoDrawBackground="false" 添加到 MXAdvancedDataGridItemRenderer 中。我在使用 ADG 的“单细胞”选择模式时遇到问题,这解决了问题。
You may want to try to put add autoDrawBackground="false" to your MXAdvancedDataGridItemRenderer. I had problems using the "single cell" selection mode for for an ADG and this fixed the problem.
试试这个(注意
rollOverColor
):干杯,
抢
Try this (note
rollOverColor
):Cheers,
Rob
您还可以通过为 AdvancedDataGrid 设置“样式”来实现此目的
}
You can also achieve this by setting 'Style' for AdvancedDataGrid
}