如何将MVVM和DataTemplateSelector从Silverlight移植到Flex? [英] How MVVM with DataTemplateSelector is portable from Silverlight to Flex?

查看:183
本文介绍了如何将MVVM和DataTemplateSelector从Silverlight移植到Flex?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里问了一个关于MVVM的问题

答案将使用 DataTemplateSelector 来获得多个视图。现在让我们说我需要移植到flex。 Flex是否具有与 DataTemplateSelector



相同的范例Silverlight声称它接近于Flex,喜欢看证明:)

解决方案

具体而言,没有DataTemplateSelector。然而,这并不奇怪,因为它们是不同的堆栈...(它们在功能奇偶性和开发者范例方面是非常相似的)在Flex中,有皮肤的概念,它们与模板非常相似。还有项目渲染器的概念,它与重复视图(List,DataGroup,DropDownList,ComboBox,DataGrid等)中的数据模板非常相似。

渲染器(最有可能是你在说什么),组件有一个可选的 itemRendererFunction 属性,它是决定使用哪个项目渲染器的函数。它允许非常动态的视图被放在演示模型之上(它们在Flex中不被称为视图模型...它们使用演示模型的原始名称...不确定为什么Silverlight将它改变为MVVM ... I对于所有其他(基于Spark的)组件,您可以使用 .setStyle('skinClass ',TheSkin)



另外,您可以使用IoC容器将Presentation Models与任何视图粘合在一起。实际上,这很简单。

沿着同样的路线,我曾经构建了一个非常小的视图映射引擎,允许您针对类型注册视图并自动进行数据绑定。很像Silverlight的Prism中的RegionManager。



如果您对Presentation Model如何适用于Flex感兴趣,我已经写了两篇关于该主题的文章:




在多个屏幕中使用演示模型



第二个链接将在周二发布,介绍如何使用在同一个展示模型的顶部有多个视图。



所以,是的。有几个解决方案来实现你想要达到的目标。没有一个是直接的,因为它们是不同的堆栈,但功能肯定存在。


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

解决方案

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.

这篇关于如何将MVVM和DataTemplateSelector从Silverlight移植到Flex?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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