通过 MXML 扩展 MXML 自定义组件 [英] Extending MXML custom components via MXML

查看:22
本文介绍了通过 MXML 扩展 MXML 自定义组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是:创建一个带有一些子组件的 MXML 组件,然后通过 MXML 扩展它以创建一个具有更多子组件的新组件,而不会丢失原始集合.换句话说

What I'd like to do: create an MXML component with some children, then extend it via MXML to create a new component with more children, without losing the original set. In other words

创建一个组件 bc.mxml

create a component bc.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">

    <s:Button id="b1" label="button1"/>
</s:BorderContainer>

然后将其扩展为单独的组件 mc.mxml

and then extend it to a separate component mc.mxml

<?xml version="1.0" encoding="utf-8"?>
<borderContainerX:bc 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:borderContainerX="borderContainerX.*">

    <s:Button id="b2" y="100" label="button2"/>
</borderContainerX:bc>

并获得一个带有 2 个按钮的组件.

and get a component with 2 buttons.

我已经看到了关于这是不可能的(1)或关于实现此目的的解决方法(23) 并且一直想知道是否随着 Flex 4 的出现发生了一些变化,或者我们是否仍然坚持使用这些解决方法线程 3 中的最后一个回复似乎暗示 Flex 4 修复了所有问题?

I've seen various threads on how this is either not possible (1) or on workarounds to accomplish this (2, 3) and have been wondering if something has changed with the advent of Flex 4 or if we're still stuck with these workarounds the last reply in thread 3 seems to hint at Flex 4 fixing it all?

推荐答案

在 Flex 4 中,您将必须覆盖mxmlContent"属性设置器,以便在父类中保留已定义的子项

In Flex 4, you will have to override your "mxmlContent" property setter in order to preserve your already defined children in a parent class

此博客条目的评论中提供了此类覆盖的一种可能实现

One of possible implementations of such a override is presented in the comment for this blog entry

快速提示 (Flex 4):再见模板——你好 mxmlContent

http://www.websector.de/blog/2009/10/02/quick-tip-flex-4-goodbye-templates-hello-mxmlcontent/

这篇关于通过 MXML 扩展 MXML 自定义组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆