如何在 MXAdvancedDataGridItemRenderer 中设置悬停颜色?

发布于 2024-10-28 12:42:48 字数 2574 浏览 5 评论 0原文

我正在尝试使用 MXAdvancedDataGridItemRenderer 为 AdvancedDataGrid 创建项目渲染器。

当我将示例自定义项目渲染器 (MXAdvancedDataGridItemRenderer) 附加到 AdvancedDataGrid 中的分层数据时,项目渲染器无法正确渲染单元格。 如果也未选择自定义渲染器,则仅将其渲染为悬停(突出显示)状态。当选择该行并将其悬停时,自定义项渲染器将仅渲染选定的单元格。

如何让自定义渲染器识别出在突出显示行时应该突出显示?

下图显示了一个示例。第一行被选中,鼠标悬停在第二个单元格上。正如您所看到的,单元格呈现为“选定”而不是“悬停”。

MXAdvancedDataGridItemRenderer 后台渲染问题

这是一个示例应用程序:

<?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'.

MXAdvancedDataGridItemRenderer background render issue

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青春有你 2024-11-04 12:42:48

您可能想尝试将 autoDrawBackground="false" 添加到 MXAdvancedDataGridItemRenderer 中。我在使用 ADG 的“单细胞”选择模式时遇到问题,这解决了问题。

<?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"
                                  autoDrawBackground="false">

  <s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{listData.label}" />

</s:MXAdvancedDataGridItemRenderer>

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.

<?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"
                                  autoDrawBackground="false">

  <s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{listData.label}" />

</s:MXAdvancedDataGridItemRenderer>
如此安好 2024-11-04 12:42:48

试试这个(注意rollOverColor):

<mx:AdvancedDataGrid x="10" y="10" width="350" height="200" rollOverColor="0xff0000" 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>

干杯,

Try this (note rollOverColor):

<mx:AdvancedDataGrid x="10" y="10" width="350" height="200" rollOverColor="0xff0000" 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>

Cheers,
Rob

梦途 2024-11-04 12:42:48

您还可以通过为 AdvancedDataGrid 设置“样式”来实现此目的

AdvancedDataGrid {
textRollOverColor: #000000;
textSelectedColor: #FFFFFF;
disabledColor: #8E8E8E;
borderColor: #454545;
alternatingItemColors: #FFFFFF, #FCFCFC;
verticalGridLineColor: #F6F6F6;
color: #000000;
selectionColor: #A0B3BE;
rollOverColor: #DBE4E6;
borderStyle: none;
borderThickness: 0;
fontSize: 12;
headerColors: #DBE4E6, #DBE4E6;
selectionDisabledColor: #FFFFFF;

}

You can also achieve this by setting 'Style' for AdvancedDataGrid

AdvancedDataGrid {
textRollOverColor: #000000;
textSelectedColor: #FFFFFF;
disabledColor: #8E8E8E;
borderColor: #454545;
alternatingItemColors: #FFFFFF, #FCFCFC;
verticalGridLineColor: #F6F6F6;
color: #000000;
selectionColor: #A0B3BE;
rollOverColor: #DBE4E6;
borderStyle: none;
borderThickness: 0;
fontSize: 12;
headerColors: #DBE4E6, #DBE4E6;
selectionDisabledColor: #FFFFFF;

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文