flex 4:自定义 CSS 值

发布于 2024-08-09 22:27:01 字数 243 浏览 7 评论 0原文

有什么方法可以为组件创建自定义 css 值并使其可用于该组件正在使用的外观类吗?例如,如果我在 css 文件中定义它:

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

有没有办法使 myCustomValuePanelSkin 中可用?

is there any way to create a custom css value for a component and have it available to the skin class that component is using? for example, if i define this in a css file:

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

is there a way to make myCustomValue available in the PanelSkin ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

独木成林 2024-08-16 22:27:01

即使组件类上没有 [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>

Even without [Style] metadata on the component class, it seems you can set CSS properties and they'll be available in the skin. As a test, I created a custom skin and attached it to SkinnableComponent, and then set a property 'special-color' via CSS. In the skin, I bound to "{getStyle('specialColor')", and it retrieved the property value that I set.

All you might be sacrificing by omitting the metadata is the autocompletion on the CSS.

My test code:

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>
丑丑阿 2024-08-16 22:27:01

您必须使用 [Style] 元数据,以下是有关此内容的更多信息: 样式元数据标签

You have to use the [Style] metadata, here's more info on this: Style metadata tag

机场等船 2024-08-16 22:27:01

您必须在 mxml 外观文件中定义主机组件类。

[HostComponent("your.component.class")]

之后,您将能够使用以下方法获取 css 文件中定义的任何样式
hostComponent.getStyle("myCustomValue")

You have to define you host component class in the mxml skin file.

[HostComponent("your.component.class")]

After this, you'll be able to get any style defined in the css file by using
hostComponent.getStyle("myCustomValue")

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