0

I asked a question here about MVVM In MVVM there can be only one View for each one View Model?

Answer would be to use DataTemplateSelector to get multiple views. Now let's say I need to port to flex. Does Flex have the same paradigm as DataTemplateSelector?

Since Silverlight claims that it is close to Flex then I'd like to see proofs :)

Community
  • 1
  • 1
user310291
  • 36,946
  • 82
  • 271
  • 487
  • 1
    Technically speaking, Silverlight and Flex are competitors within a solution space (Rich, non-HTML web applications) but that is where the "closeness" ends. There is not meant to be any portability between them. – Dave White Apr 09 '11 at 20:28
  • @Dave White: portability, no. But they are extremely similar in most regards. In some cases, they are so similar that a simple XSLT transform would handle a port. In other cases, implementation details are different, but the concepts are strongly comparable. I have yet to find something that I can do in one framework but can't do in the other. – Brian Genisio Apr 10 '11 at 01:24
  • @Brian: My comment was not to suggest that there was not a feature parity between the two. Only that there is no direct path between them. The .NET Framework and Silverlight libraries do not exist in the Flex environment. – Dave White Apr 10 '11 at 01:42
  • @Dave White: Gotcha. I can't disagree with that :) – Brian Genisio Apr 10 '11 at 01:44

1 Answers1

1

Specifically, there is no "DataTemplateSelector". That is not surprising, though, because they are different stacks... (They ARE extremely similar to each other with regards to feature parity and developer paradigm) In Flex, there is the concept of skins, which are very similar to templates. There is also the concept of item renderers, which closely resemble data templates in repeated views (List, DataGroup, DropDownList, ComboBox, DataGrid, etc)

In the case of item renderers (most likely what you are talking about), the components have an optional itemRendererFunction property which is a function that decides which item renderer to use. It allows for extremely dynamic views to be slapped on top of Presentation Models (they are not called View Models in Flex... they use the original name of Presentation Model... not sure why Silverlight ever changed it to MVVM... I digress).

As for skins on all other (Spark-based) components, you can change the skins at runtime using .setStyle('skinClass', TheSkin)

In addition, you can use IoC containers to glue together Presentation Models with any view. This is actually very easy.

Along the same lines, I once built a very tiny view mapping engine that lets you register views against types and the data binding happens automatically. A lot like the RegionManager in Prism for Silverlight.

If you are interested in how Presentation Model fits within Flex, I have written two articles about the topic:

MVVM vs Presentation Model Presentation Model for using in Multiple Screens

The second link will have a follow-up posted on Tuesday that describes how you use multiple views on top of the same Presentation Model.

So, yes. There are several solutions to achieve what you want to achieve. None of them are direct, because they are different stacks, but the functionality is certainly there.

Brian Genisio
  • 47,787
  • 16
  • 124
  • 167
  • Thanks that's exactly what I was looking for and more for the articles that are very interesting and unique :) – user310291 Apr 10 '11 at 05:43
  • You said : "If you do a Google search today for “MVVM and Flex”, the first post is by somebody who claims that MVVM is not a good fit for Flex. I couldn’t disagree more. Out of the box, the Flex framework makes it much easier to implement a Presentation Model than similar MVVM implementations in Silverlight. That is not to say that there aren’t good third-party libraries that make it easier in Silverlight, but without any help, it is easier to do in Flex. " – user310291 Apr 10 '11 at 05:50
  • That's why I asked the question because though I do think MVVM in concept is good in implementation that seems over-complicated in silverlight "out of the box" so my next question coming soon :) – user310291 Apr 10 '11 at 05:51
  • So here is my subsequent question http://stackoverflow.com/questions/5610066/presentation-model-in-flex-vs-presentation-model-in-silverlight-advantages-and-d – user310291 Apr 10 '11 at 06:00