IronPython或IronRuby是否非常适合WPF/Silverlight中的MVVM模式? [英] Are IronPython or IronRuby well-suited for the MVVM pattern in WPF/Silverlight?

查看:80
本文介绍了IronPython或IronRuby是否非常适合WPF/Silverlight中的MVVM模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很高兴在WPF和Silverlight应用程序中将Model-View-ViewModel(MVVM)模式与C#结合使用.声明性XAML标记和数据绑定是无价的-没有它们,我简直无法生存.但是,哈里·皮尔森(Harry Pierson)的此话题动态语言方面的知识使我对学习动态语言感到兴奋,并且我想在一个新项目中尝试一下.我一直很喜欢阅读 IronPython In Action ,它确实包含一些WPF示例-但仅用于命令性样式的代码.

I've been very happily using the Model-View-ViewModel (MVVM) pattern in WPF and Silverlight apps in combination with C#. Declarative XAML markup and data binding are invaluable - I just can't live without them. But, this talk by Harry Pierson on dynamic languages got me excited about learning a dynamic language, and I'd like to try one out in a new project. I've been enjoying reading IronPython In Action, and it does contain a few WPF examples - but only with imperative-style code.

在MVVM应用程序(与C#相比)的ViewModel和Model层上使用IronPython或IronRuby有什么想法?哪些功能使它们具有吸引力(或缺乏吸引力)?我对基本优点/局限性(例如AOP,鸭式打字,猴子补丁,静态类型限制等)和实用的优点/局限(例如性能,

What are your thoughts on using IronPython or IronRuby at the ViewModel and Model layers in MVVM apps (compared to C#)? Which features of make them attractive (or unattractive)? I'm interested in fundamental advantages/limitations (e.g. AOP, duck typing, monkey patching, static type limitations, etc) and practical ones alike (e.g. performance, no current IronPython Studio for v2, etc). Will any limitations improve with C# 4.0?

谢谢

大卫

推荐答案

Shay是正确的,但仅适用于Silverlight,而我还没有使用Silverlight和IronRuby.您可以将命令与纯IronRuby和WPF绑定并使用命令.我假设这也适用于IronPython,因为它们都使用 ICustomTypeDescriptor .需要警告的是,您需要比IronRuby 0.9更新的DLR构建事件.

Shay is right, but only for Silverlight and I've not used Silverlight and IronRuby. You can bind and use commands with pure IronRuby and WPF. I'm assuming this also applies to IronPython as they both use ICustomTypeDescriptor. there is a caveat, you'll need a DLR build more recent than IronRuby 0.9 for events.

要创建IronRuby命令,您需要实现事件.有关更多实施和IronRuby中包含CLR事件的接口

To create an IronRuby command, you need to implement events. See this SO question for more Implementing and Interface in IronRuby that includes CLR Events

关于创建可以参与绑定的IronRuby对象,需要处理的是attr读取器/写入器必须用于DLR才能将其视为属性.

As for creating an IronRuby object that can participate in binding, the deal is a an attr reader/writer needs to be used for the DLR to see it as a property.

class Bindable
  attr :some_property, true
end

我有一些要点. 命令示例一个带有绑定的简单ViewModel示例基于XML Builder的xaml库在示例中使用.这些对我有用.

I've got a few Gists about it. A Command Example, A simple ViewModel Example with Binding And the XML Builder based xaml library used in the examples. These worked for me.

有局限性. XamlLoader无法从CLR中看到IronRuby类.这意味着您的视图确实很愚蠢(后置零代码),或者它们来自C#dll.这也意味着,如果不使用C#,就无法创建带有任何代码的自定义控件或用户控件.

There are limitations. XamlLoader can't see IronRuby classes from the CLR. This means your views are REALLY dumb (zero code-behind), or they come from a C# dll. It also means that you can't create custom or user controls that have any code behind without going to C#.

虽然我在IronRuby/WPF中没有完全烘焙的MVVM应用程序,但我认为所有内容都已经准备就绪,我已经到达了.

While I don't have a fully baked MVVM app in IronRuby/WPF, I think all the pieces are in place and I'm getting there.

这篇关于IronPython或IronRuby是否非常适合WPF/Silverlight中的MVVM模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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