5

コンポーネントのカスタムcss値を作成し、そのコンポーネントが使用しているスキンクラスで使用できるようにする方法はありますか?たとえば、これをcssファイルで定義した場合:

s|Panel{
  skinClass: ClassReference("PanelSkin");
  myCustomValue: #CCCCFF;
}

myCustomValueで利用できるようにする方法はありPanelSkinますか?

4

3 に答える 3

5

コンポーネントクラスに[Style]メタデータがなくても、CSSプロパティを設定でき、スキンで使用できるようになります。テストとして、カスタムスキンを作成し、それをSkinnableComponentにアタッチしてから、CSSを介してプロパティ「special-color」を設定しました。スキンでは、「{getStyle('specialColor')」にバインドし、設定したプロパティ値を取得しました。

メタデータを省略して犠牲にしているのは、CSSのオートコンプリートだけです。

私のテストコード:

SkinTest.mxml:

<?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/halo" minWidth="1024" minHeight="768">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Style>
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace mx "library://ns.adobe.com/flex/halo";

    s|SkinnableComponent {
        skin-class: ClassReference("skins.CustomSkin");
        special-color: blue;
    }
</fx:Style>

<s:SkinnableComponent width="300" height="300"/>
</s:Application>

CustomSkin.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/halo" width="400" height="300">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<s:Rect left="0" top="0" right="0" bottom="0">
    <s:fill>
        <s:SolidColor color="{getStyle('specialColor')}"/>
    </s:fill>
</s:Rect>
</s:SparkSkin>
于 2009-11-20T09:38:51.710 に答える
1

[Style]メタデータを使用する必要があります。これに関する詳細は次のとおりです:Styleメタデータタグ

于 2009-11-05T22:25:51.697 に答える
0

mxmlスキンファイルでホストコンポーネントクラスを定義する必要があります。[HostComponent( "your.component.class")]

この後、hostComponent.getStyle( "myCustomValue")を使用して、cssファイルで定義された任意のスタイルを取得できるようになります。

于 2009-11-23T12:22:22.183 に答える