简体   繁体   English

带皮肤的按钮的Flex DataGrid

[英]Flex DataGrid with Button with Skin

Try as I may, I am not able to skin a spark Button, when I place the button within a spark dataGrid. 尝试尝试时,将按钮放在spark dataGrid中时,无法为Spark Button蒙皮。 I am constrained to using the halo theme. 我被限制使用光晕主题。

I have created the button renderer in a separate mxml file; 我已经在单独的mxml文件中创建了按钮渲染器; I have separate buttons outside the dataGrid that show the skin correctly, so I am sure that there is nothing wrong with the skin. 我在dataGrid外部有单独的按钮,可以正确显示皮肤,因此我确信皮肤没有任何问题。 The whole point of this is to use the same skin inside the dataGrid as outside 整个过程的重点是在dataGrid内部使用与外部相同的外观

The following code shows the same behavior that I am seeing; 以下代码显示了我所看到的相同行为; in this case the renderer is created in line. 在这种情况下,渲染器是在线创建的。 It seems like the skinClass is not respected. 似乎skinClass不被尊重。 Or is there another way to do it. 还是有另一种方法可以做到这一点。

<s:DataGrid id="dg" width="500" dataProvider="{employees2}">
    <s:columns>
        <s:ArrayList>
            <s:GridColumn dataField="name" headerText="Name">
                <s:itemRenderer>
                    <fx:Component>
                        <s:GridItemRenderer>
                            <s:Button label="Press Me"
                                      top="0" bottom="0" left="0" right="0"
                                      skinClass="MyButtonSkin" />
                        </s:GridItemRenderer>
                    </fx:Component>
                </s:itemRenderer>
            </GridColumn>   
        </s:ArrayList>
    </s:columns>
</s:DataGrid>

In file MyButtonSkin.mxml 在文件MyButtonSkin.mxml中

<?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
         minWidth="21" minHeight="21" 
         alpha.disabled="0.5">

<fx:Metadata>
    <![CDATA[ 
    /** 
     * @copy spark.skins.spark.ApplicationSkin#hostComponent
     */
    [HostComponent("spark.components.Button")]
    ]]>
</fx:Metadata>

<fx:Script fb:purpose="styling">
    <![CDATA[         
        /* Define the skin elements that should not be colorized. 
        For button, the graphics are colorized but the label is not. */
        static private const exclusions:Array = ["labelDisplay"];

        /** 
         * @private
         */     
        override public function get colorizeExclusions():Array {return exclusions;}

        /**
         * @private
         */
        override protected function initializationComplete():void
        {
            useChromeColor = true;
            super.initializationComplete();
        }  

    ]]>        
</fx:Script>

<!-- states -->
<s:states>
    <s:State name="up" />
    <s:State name="over" />
    <s:State name="down" />
    <s:State name="disabled" />
</s:states>

<!-- layer 2: fill -->
<!--- @private -->
<s:Rect id="fill" left="1" right="1" top="1" bottom="1" radiusX="10">
    <s:fill>
        <s:LinearGradient rotation="90">
            <s:GradientEntry color="0xFAFAFA" 
                             color.over="0xBBBDBD" 
                             color.down="0xAAAAAA" 
                             alpha="0.85" />
            <s:GradientEntry color="0x808080" 
                             color.over="0x9FA0A1" 
                             color.down="0x929496" 
                             alpha="0.85" />
        </s:LinearGradient>
    </s:fill>
</s:Rect>

<!-- layer 8: text -->
<!--- @copy spark.components.supportClasses.ButtonBase#labelDisplay  -->
<s:Label id="labelDisplay"
         textAlign="center"
         maxDisplayedLines="1"
         horizontalCenter="0" verticalCenter="1" verticalAlign="middle">
</s:Label>

</s:SparkButtonSkin>

It appears that scaling the button to the size of the grid item does not size the corner radius. 似乎将按钮缩放到网格项目的大小不会调整角半径。

I ended up with a button 200x200 pixels with a corner radius of 6 pixels; 我最后得到一个200x200像素的按钮,其转角半径为6像素; it just couldn't be seen. 只是看不到。 I upped the value to 25 and now I can see it 我将值提高到25,现在我可以看到它了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM