开发者

resizing list components upon dataProvider change

开发者 https://www.devze.com 2023-03-19 16:19 出处:网络
I have a component that contains a list that implements a custom renderer.I use this component as a tooltip, keeping one in memory and just altering the databindings as necessary.

I have a component that contains a list that implements a custom renderer. I use this component as a tooltip, keeping one in memory and just altering the databindings as necessary.

Something like this where TTComponent is a class that extends Canvas:

<s:TTComponent>
  <s:BorderContainer>
    <s:List id='lstItems' dataProvider="{data.Items}" width="50%" borderVisible="false" contentBackgroundColor="#222222">
      <s:layout>
        <s:VerticalLayout useVirtualLayout="false" requestedMinRowCount="1"/&g开发者_JS百科t;
      </s:layout>
      <s:itemRenderer>
        <fx:Component>
          <s:ItemRenderer>
            <s:HGroup>
              <s:Label text="{data.Value}" paddingLeft="6" />
              <s:Label text="{data.Name}" />
            </s:HGroup>
          </s:ItemRenderer>
        </fx:Component>
      </s:itemRenderer>
    </s:List>        
  </s:BorderContainer>
</s:TTComponent>

Now, the driver code looks like this for the mouse over:

if (tt == null) {
  tt = new TTComponent();
}
tt.data = data;
PopUpManager.addPopUp(tt, this);

And, of course, the mouse out:

PopUpManager.removePopUp(tt);

Now, what happens is when data containing many items is set to tt.data, the list resizes itself larger and displays fine. However, after this, if data containing few items is set to tt.data, the component momentarily displays larger than it needs to be, then resizes itself smaller.

What I'd like to do is have the component resize itself before it displays, so I don't see the resize on screen. Any idea on how to accomplish this?


First, I would compel you to consider creating the component once and just showing / hiding it / moving it when needed rather than using pop up manager. That's how I would typically do something similar to what you're attempting. It will perform better and probably fix this issue on its own. Just a thought.

Secondly, after you rebind new data to it, try these :

Tell it needs to resize :

tt.invalidateDisplayList();

Also, you might need to tell it you changed the data by refreshing the data if an ArrayCollection:

data.refresh();

Let me know if that doesn't do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消