How MVVM with DataTemplateSelector is portable from Silverlight to Flex?

风格不统一 提交于 2020-01-06 15:49:12

问题


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 :)


回答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.



来源:https://stackoverflow.com/questions/5607619/how-mvvm-with-datatemplateselector-is-portable-from-silverlight-to-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!