开发者

MVC in Silverlight

开发者 https://www.devze.com 2022-12-15 18:03 出处:网络
When I discovered MVC (first with ASP.NET MVC), I thought it was the holy grail of software paradigms.

When I discovered MVC (first with ASP.NET MVC), I thought it was the holy grail of software paradigms.

I recently started to dabble into Silverlight and noticed that the VS projects start off with pages similar to Forms (Web and Win) with code behinds and .xaml as the design.

Is there an equivalent to MVC in Silverlight (both for web and desktop applications)? Something supported by Microsoft (like ASP.NET MVC) where resources and help are plentiful?

I can't see myself returning开发者_JS百科 to code-behinds after discovering MVC. Is this a naive idea when it comes to Silverlight because it's different than ASP.NET and can't easily implement MVC to it?


Silverlight is pretty close to WPF, where the MVVM design pattern fits very well.

Unfortunately, the current incarnations of SL don't fully support MVVM because it lacks certain types (e.g. ICommand, IIRC), but with Silverlight 4, MVVM should be fully supported.


There's no Microsoft-supported MVC framework for Silverlight. But MVC isn't a natural architecture for Silverlight applications anyway. The implied architecture of Silverlight and WPF is model - view - view model (MVVM), and this is supported directly in Silverlight via the data binding infrastructure. In MVVM, instead of having controllers talking to decoupled views, you create view model classes which encapsulate the data and behaviour, and the view realises itself from them using data binding.

The closest Microsoft has to a framework for Silverlight and WPF MVVM development is Prism. This is far from a complete solution, but you can supplement it with other third-party toolkits such as Josh Smith's MVVM Foundation.


I have had some success using Laurent Bugnion's MVVMLight framework. http://mvvmlight.codeplex.com/

0

精彩评论

暂无评论...
验证码 换一张
取 消