Simple F# ViewModel for Silverlight MVVM
The wonderful F# Snippets community site continues to be a source of great inspiration, guidance and samples in the practical use of F# in all sorts of domains
The latest addition is a "Simple F# ViewModel for Silverlight MVVM". F# is an excellent language for implementing Silverlight View Model components and using them in Expression Blend.
Silverlight default architecture is Model-View-ViewModel. This code gives full design time support for Microsoft Expression Blend. The F# ViewModel is seen as strongly typed data source in the Blend UI. There are two properties binded to the view: HiLabel (OneWay data binding) and MyName (TwoWay data binding). ViewModel implements the INotifyPropertyChanged to support the binding. The view project (HelloApp) is made with Blend (by designers) and it is Silverlight 5.0 project. The view codebehind is c# file and it has only this.DataContext -assignment. The viewmodel project (HelloApp.ViewModel) is F# Silverlight 4.0 library. It is made with VS2010 and F# (by developers). It contains the logical functionality of the current view.
[ followed by the code of course. ]
You can also find some good MVVM guidance in the F# Online Templates on Visual Studio Gallery (In Visual Studio 2010, use New Project -> Online Templates -> search for "fsharp")
don
Comments
Anonymous
June 03, 2011
Hi Mr. Don Syme Thank for your blog of 'Simple F# ViewModel for Silverlight MVVM'. I have a Issue about FSharp type indent in WCF enviroment When it use with type ident in FSharp coding, run it in WCF host, and call it from client, the errors occured as below System.InvalidOperationException: There was an error while trying to deserialize parameter http://tempuri.org/:.... Please see InnerException for more details. ---> System.InvalidOperationException: The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized //------------------------------------------------------------ //It's wrong with type indent [<DataContract>] type A()= [<DefaultValue>] val mutable _Column:string [<DataMember>] member x.Column with get ()=x._Column and set v=x._Column<-v [<Sealed>] [<DataContract>] type B= inherit A new ()={inherit A()} new (para) as x=new B() then //Type indent is 'x' do x.Initialize () member x.Initialize ()= //TODO Initialize //------------------------------------------------------------ But it's right when it's without type ident! [<Sealed>] [<DataContract>] type B= inherit A new ()={inherit A()} new (para)=new B() then do //TODO Initialize How can I correct this? Thanks & Regards Zhou [ Don says; Hi Zhou, it is best to ask this on www.stackoverflow.com ]Anonymous
June 03, 2011
Hi Don, thank you for your quick guid.