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

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

问题描述

我在这里问了一个关于 MVVM 的问题 在 MVVM 中,每个视图模型只能有一个视图吗?

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

答案是使用 DataTemplateSelector 来获取多个视图.现在假设我需要移植到 flex.Flex 是否与 DataTemplateSelector 具有相同的范例?

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?

既然 Silverlight 声称它接近 Flex,那么我想看看证明 :)

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

推荐答案

具体来说,没有DataTemplateSelector".不过,这并不奇怪,因为它们是不同的堆栈......(它们在功能奇偶校验和开发人员范式方面非常相似)在 Flex 中,有皮肤的概念,它与模板非常相似.还有项渲染器的概念,它非常类似于重复视图中的数据模板(List、DataGroup、DropDownList、ComboBox、DataGrid 等)

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)

在项目渲染器的情况下(最有可能是你正在谈论的),组件有一个可选的 itemRendererFunction 属性,它是一个决定使用哪个项目渲染器的函数.它允许在演示模型之上添加极其动态的视图(它们在 Flex 中不称为视图模型……它们使用演示模型的原始名称……不知道为什么 Silverlight 将其更改为 MVVM……我离题了).

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

对于所有其他(基于 Spark 的)组件的外观,您可以在运行时使用 .setStyle('skinClass', TheSkin)

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

此外,您可以使用 IoC 容器将展示模型与任何视图粘合在一起.这其实很简单.

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

同样,我曾经构建了一个非常小的视图映射引擎,可以让您根据类型注册视图,并且数据绑定会自动发生.很像 Silverlight 的 Prism 中的 RegionManager.

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.

如果您对演示模型如何适应 Flex 感兴趣,我已经写了两篇关于该主题的文章:

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

MVVM 与演示型号多屏展示模型

第二个链接将在周二发布后续文章,描述您如何在同一个演示模型之上使用多个视图.

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.

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

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