Silverlight 2 UI pattern - silverlight

I have to build small (for now) admin app in Silverlight2, and would like to use some pattern for binding UI with my BL/DAL.
I found view-model-viewmodel and mvp/mvc patterns, where first one (V/M/VM) is specially suited for WPF apps, because it uses rich capabilities of WPF data-binding options. What do you suggest? Can you write simple example of V/M/VM for SL2?

Nikhil Kothari has a great set of examples (with code) on M-V-VM in Silverlight as well as a framework built with some very nice extra features. You should definitely check them out.
M-V-VM in Silverlight

The Patterns & Practices group at Microsoft has put together some guidance around doing WPF and Silverlight applications.

You might want to look at CSLA.NET for Silverlight. I've heard good things about it but haven't gotten around to try it yet myself.
CSLA .NET for Silverlight is a subset
of CSLA .NET targeted at the
Silverlight platform. CSLA .NET for
Silverlight offers nearly all the
benefits of CSLA .NET on Silverlight,
including data binding, validation,
business rules, authorization, n-level
undo and persistence.
The result is that CSLA .NET for
Silverlight enables the creation of a
rich object-oriented business layer
running on the Silverlight client,
that can transparently communicate
with CSLA .NET objects running on the
web and application servers.

Silverlight has also very powerful data-binding, so there is no problem with that.
The missing piece in Silverlight that affects more to the Model-View-ViewModel pattern is that it doesn’t implements commands like WPF. Here is an article by Josh Smith that reproduces the command pattern of WPF in Silverlight.

Shawn Wildermuth of Wildermuth.com wrote an article about the MV-VM Pattern, check it out, here is the link of the article "Model-View-ViewModel In Silverlight 2 Apps"

Norwegian developer Gjøran had a very nice presentation/demo at MSDN Live about writing business apps in WPF. Really it was about using Presentation Model with Silverlight/WPF. Have a look at the source code from this article on his blog (sorry, the slides are in Norwegian only). Presentation Model + silverlight 2 rocks!!!

Related

MVP or MVVM framework for both WPF and .NET CF 3.5 development

I am creating a draft architecture outline for a disconnected client-server platform, that involves multiple different client types. I need to support: web clients, desktop workstations and mobile devices (WM 6.x now and Android later).
I am searching for a MVP or MVVM based framework that would let me to reuse as much of the code and architecture as possible between clients, while:
using WPF for desktop development
using .NET CF 3.5 for Windows Mobile development
This framework does not obviously need to support Android, however I am considering Mono for Android to develop the Android client (for easier maintenance of the whole platform), so portability would have been an added asset.
So far I ruled out:
Prism (does not support WM based mobile devices - Windows Phone 7 only)
MVC# (does not support WPF)
I would appreciate any hints that would aid in researching the subject further.
These MVVM Frameworks work with Windows Phone 7:
Caliburn Micro
MVVM Light (it doesn't advertise it, but I've been to a demo where it was used on WP7)
ReactiveUI (Uses the Reactive Extensions for .NET)
My personal favorite is ReactiveUI, but if you've never used the Reactive Extensions it can be a brain burner at first.
As for UI Composition (you mentioned Prism), there aren't a lot of options, mostly due to reflection restrictions on the phone. I have seen an article where someone got basic MEF working on the phone and MEF is probably all most people need in this situation. You can check out that article here.
Hope this helps.
In my opinion, this would be a custom Framework with a mix of UI Processes for different client types. The business logic or entities can definitely be reused to suit the needs of the view.
I did the same research and I concluded the following (which I did not implement yet):
There aren't any open source MVVM frameworks that support .NETCF. You
can only find MVC or MVP, but not MVVM.
Suggestion: get the source code of an Open Source MVVM framework that supports the Full/Desktop .NET, and see if you can adapt it(so that it recompiles) to the .NETCF. I found the following two, which also support the other platforms that you mentioned:
MVVM FX for Windows Forms and Visual WebGUI - Home
MugenMvvmToolkit
Other than that, I don't see any other way of doing this.
HTH,
MVVM wouldn't make much sense in Windows Mobile + .NETCF since you don't have INotifyPropertyChanged and implementing Model-View-Presenter in WPF or any INotifiyPropertyChanged supported framework wouldn't be as effective as Model-View-ViewModel
You can share assets between the full and compact framework by moving most of the business logic into a seperate class library (or several) that target the .NETCF. You can reference a .NETCF library from a full framework project, but not the other way around.
Check out this very good article by Daniel Moth describing how to share assets between the compact and full framework:
http://msdn.microsoft.com/msdnmag/issues/07/07/ShareCode/default.aspx

Good way for experience WPF developer to learn Silverlight

I'm a developer with WPF experiences, my next project will use Silverlight. I have read some articles on the internet (almost all msdn and silverlight.net) and I think that they aren't much different. Anyway, I still have questions that I'm not sure.
What is different between WPF 4 and Silverlight 4? (I found an article on msdn but its based on .NET framework 3.5)
Are there any resources for learning Silverlight that are good for experience WPF developer?
Do I need a book on Silverlight?
I personally really like the course posted here:
http://channel9.msdn.com/learn/courses/Silverlight4/
I don't know what you intend to develop using Silverlight. But it's a good start if you like to develop business applications using Silverlight.
WPF has hardware-accelerated full faceted 3D support
WPF has direct access to the full .NET framework
WPF can take full advantage of the hardware on the system.
Silverlight allows you to create a single app that works across browsers, operating systems.
You can use Silverlight for Windows Phone 7 development
For Books, I would recommend Silverlight Recipes and Microsoft Silverlight 4 Data and Services Cookbook.

Silverlight and Line of Business Applications

I'm trying to understand the best way to create line of business applications in Silverlight. I hear about entity framework and RIA Services and prism and I am completely confused. If I want to create a line of business application that pushes data to the the client application, which framework should I use?
Well, Prism in the context of Silverlight is definitely not the Mozilla project mentioned in the other answer. Prism is a Silverlight/WPF framework from Microsoft. The "Overview" paragraph on the following page explains it pretty well:
http://www.codeplex.com/CompositeWPF
I would recommend that you look into RIA services and the MVVM pattern to start with. Rather than Prism (which is a large framework that can seem daunting at first), I would recommend that you check out one of the smaller MVVM frameworks. I use MVVMLight from Laurent Bugnion (Sorry, I tried linking to it but stackoverflow won't let me. Just google it.) and that work fine for my requirements. Once you are comfortable with that you can decide whether you need the power of Prism or not.
/Henrik
You will likely want to use Silverlight + RIA Services. This is really designed exactly for that scenario.
I recommend reading Brad Abram's blog for info, in particular, What is .NET RIA Services?
He also wrote a very long, detailed series about RIA Services.
RIA Services gets data from the LOB application to your Silverlight client (and vice versa).
Entity Framework is the way to get data from your database to your LOB application (and vice versa).
Prism is a project Mozilla has developed that makes a web application look like a desktop application: http://www.riapedia.com/2007/10/26/prism_gives_web_apps_desktop_space
You can user WCF Ria services (very nice and usable data access) and silverlight. Prism is a very nice pattern for architecting modular applications, but I think that it would be an overhead if you want a simple application. MVVM is what you are looking for. MVVM is the design pattern depicting the presentation interacting with the model, but still you could avoid this also, if you want something pretty simple and quick. The learning curve from my pov includes (in order): Silverlight, WCF Ria Services, MVVM, Prism.

Silverlight Design Architecture

Is there a good Silverlight Design Architecture?
There is Prism it was originally designed for WPF but there is now a Silverlight release.
Also there is Caliburn, an "Application Framework for Silverlight and WPF".
You could take a look at Rocky Lhotka's CSLA.NET for Silverlight - CslaLight
Soon, Microsoft will be releasing a new version of Prism (though unlike the earlier answer), the Silverlight version of Prism is just a proof of concept. The PnP team hope to have a full release in the next couple of months. The prevailing story today is to use the same MVVM pattern that WPF has had success with (searching for Silverlight and MVVM will yield a lot of info).

Convert WPF Application to SilverLight

Is it possible to convert an existing WPF Application to SilverLight automatically/with minimal effort?
I would argue that you CAN port Silverlight to WPF with minimal effort. I spent 2 hours porting and application I spent 3 weeks writing. I would argue that those 2 hours spent would categorize as minimal effort.
Sure, you need to create a new project, add the files to the new project and tweak them.
Since Silverlight is a subset of WPF its allot easier to go from Silverlight to WPF than the other way around.
For business logic and non-UI code your code should port almost straight across. I had some minor issues around authentication, as Silverlight 2 will pick up any authentication information in the browser, while in WPF you have to role your own login screen and manage cookies etc.
For the XAML it will port straight across if you don't style your controls. If you style your controls the use of the Visual State Manager, currently missing in WPF, will make things a little trickier. You can either re-style your controls in WPF using Triggers, or you can use the VSM implementation for WPF done by John Gossman. Microsoft have announced that they will add the VSM to WPF to make the two frameworks more compatible.
The perhaps most important reuse tough, is skills and experience. Since the two platforms are so similar you will be able to reuse all your skills in WPF.
I recently did a blog post about the Dive Log sample application and how I ported it from Silverlight 2 to WPF. Might give you some idea of the process.
Not really. I have found some articles regarding the multi-targeting option for WPF and Silverlight at the same time. At this moment, if you are not using PRISM, it is quite a challenge to target both of them, fortunately achievable.
What do you need to have in mind is that Silverlight uses a smaller (thus more limited) library than WPF.
In response to the comments:
Actually, there is already support for silverlight in PRISM (v2). The idea of PRISM is to provide guidance to developing applications not only using WPF but using Silverlight also - Prism V2 formally was known as Composite Application Guidance for WPF and Silverlight.
By using PRISM for silverlight capabilities, it would give you the warranty that your code would work on both platforms with minimal changes, if none (except maybe the different project types for visual studio).
But of course, if you already started developing your application, you would need to change your code to use PRISM.
Will and Bogdan's answers are correct. The keyword here is "minimal".
Rob Eisenberg has a list of differences here (though this was pre-RTW).
List of Differences in WPF & Silverlight
No. Silverlight runs in its own cut-down version of the CLR. It also is WPF-like, not WPF. You'll have to do a fair amount of work to convert it.
Times have changed. Check out Portable Class Libraries, now supported in .NET 4.0. You can build assemblies that can be used on different supported platforms: WP7, Silverlight WPF and even XBOX applications.
Here is a thread about this:
http://silverlight.net/forums/t/3898.aspx

Resources