--- In [email protected], "Thomas, Erik" <erik_tho...@...> wrote: > > Does anyone have a code sample of how I can supply a different > itemRenderer to a List based on the data Type of the item in any given > row? > > I have a heterogeneous collection of Types in an ArrayCollection > (Property Sheet or User Preferences list) and want to render each row > differently based on the data Type of the row item. > > For those of you familiar with MS WPF, it includes the notion of > something called a "DataTemplate" which is essentially an Item Renderer > that is used by the framework to render a particular data Type in a > heterogeneous collection or on a form. I'd like to do the same thing in > Flex within a List. > > Is there such a notion in Flex? Can it be done simply? > > I've tried implementing a Factory pattern where I supply a single > itemRenderer (VBox) class to the List component which is an ActionScript > class that simply overrides the "data" setter, and tests the Type of the > "data" property (the row item type) and if it's a certain Type it > instantiates or replaces a child container that properly renders the > data based on its Type. This is not a simple pattern to follow or > communicate. I'd like to find a simpler way. > > I've also tried using a single renderer with multiple top level > components that use data binding to dynamically set "includeInLayout" > and "visible" so only one of the top level components will render. This > works, but the performance on a large list is abysmal in our ad hoc > tests. Simple renderers not using "includeInLayout" were much faster. > > I've also tried using States to determine which part of the mxml to > render based on the Type, but the pattern is just too complicated and > too verbose. > > I'm in search of the cleanest possible pattern to recreate what you get > out of the box with WPF, as I am sure someone at Adobe thought of this > (it's an amazingly common use case), but it's just a matter of my > learning how to do this.
I have an extended tile list on my Blog that has a styleFunction. If you're willing to think in different directions, there's a lot you an do with styles. Once you have the custom styles set up, it's pretty easy and intuitive for someone else to pick it up and run with it. HTH; Amy

