flex 4:自定义 CSS 值
有什么方法可以为组件创建自定义 css 值并使其可用于该组件正在使用的外观类吗?例如,如果我在 css 文件中定义它:
s|Panel{
skinClass: ClassReference("PanelSkin");
myCustomValue: #CCCCFF;
}
有没有办法使 myCustomValue
在 PanelSkin
中可用?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即使组件类上没有 [Style] 元数据,您似乎也可以设置 CSS 属性,并且它们将在皮肤中可用。作为测试,我创建了一个自定义皮肤并将其附加到 SkinnableComponent,然后通过 CSS 设置属性“special-color”。在皮肤中,我绑定到“{getStyle('specialColor')”,它检索了我设置的属性值。
省略元数据可能会牺牲 CSS 的自动完成功能。
我的测试代码:
SkinTest.mxml:
CustomSkin.mxml:
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:
CustomSkin.mxml:
您必须使用 [Style] 元数据,以下是有关此内容的更多信息: 样式元数据标签
You have to use the [Style] metadata, here's more info on this: Style metadata tag
您必须在 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")