0

我找不到在 Spark DataGrid 中删除或隐藏 caretIndicator 的简单方法,因此如果没有更好的方法,我将在此处发布解决方案。

4

1 回答 1

1

这似乎有效。要隐藏 caretIndiator,我们必须基于 spark.skins.spark.DataGridSkin 创建一个新的数据网格皮肤。然后在该皮肤中将笔画的 alpha 或矩形的 alpha 设置为 0。

方法一:

MXML

<s:DataGrid skinClass="view.skins.AbstractDataGridSkin"/>

抽象数据网格皮肤

<?xml version="1.0" encoding="utf-8"?>
<spark:DataGridSkin 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
    xmlns:spark="spark.skins.spark.*" 
    xmlns:skins="view.skins.*"
    >
    <fx:Component id="caretIndicator">
        <s:Rect implements="spark.components.gridClasses.IGridVisualElement" alpha="0">
            <fx:Script>
                <![CDATA[
                    import spark.components.DataGrid;
                    import spark.components.Grid;

                    /**
                     * @private
                     */
                    public function prepareGridVisualElement(grid:Grid, rowIndex:int, columnIndex:int):void
                    {

                        const dataGrid:DataGrid = grid.dataGrid;
                        if (!dataGrid)
                            return;

                        const color:uint = dataGrid.getStyle("caretColor");
                        caretIndicatorFill.color = color;
                    }
                ]]>
            </fx:Script>

            <s:stroke>
                <!--- @private -->
                <s:SolidColorStroke id="caretIndicatorFill" color="0x0167FF" weight="0" alpha="0"/>
            </s:stroke>
        </s:Rect>
    </fx:Component>
</spark:DataGridSkin>

方法二:

还有另一种方法涉及复制默认数据网格皮肤并删除 caretIndicator 属性。这样可能更好:P。

方法三:

这也有效:

<spark:DataGridSkin 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
    xmlns:spark="spark.skins.spark.*" 
    xmlns:skins="view.skins.*"
    initialize="caretIndicator = null" />
于 2013-03-20T19:59:52.470 回答