Oct 19 2009

Visual Studio 2010 Beta 2 and updated Silverlight Toolkit available

Lot of news this week!

Visual Studio 2010 and .NET Framework 4 Beta 2 are now available for download here, Jeff Beehler has posted some useful info about this “go live” release.

The new Silverlight Toolkit October 2009 Release is also available on Codeplex featuring Visual Studio 2010 support and various improvements on existing components (like drag-and-drop for items controls).

Read these posts by Tim Heuer and Jeff Wilcox for more details and enjoy!


Oct 15 2009

Silverlight and ViewModel meet F#

Many MVVM implementations are available on the net, personally I love the approach used by Laurent Bugnion in the MVVM Light toolkit and Michael Sync in the Silverlight MVVM toolkit (Jeremiah Morril have posted a great article about this pattern, don’t forget to read it here).

All these examples use C#, what about F# for describing ViewModel classes? F# is a very powerful and readable language and permits to perform operations using a small amount of code. Last, but not least, at this time it’s a first citizen .NET language and can be easily used in Silverlight applications as well.

How can we build a Silverlight MVVM solution using F#?

First of all, download and install the F# for Silverlight templates and samples.

Let’s start by defining a simple F# ViewModel class containing a simple “Name” property and a “SearchCommand”, this one using the DelegateCommand implementation available in Prism:

namespace SilverlightViewModelFSharp.ViewModels

open System.ComponentModel
open Microsoft.Practices.Composite.Presentation.Commands;
open System.Windows

type MainPageVM() =

   //Definition of the PropertyChanged event
   let event = Event<PropertyChangedEventHandler, PropertyChangedEventArgs>()

   //Definition of the "name" property
   let mutable name = "This is the value of a property defined in the F# ViewModel"

   //Definition of a test Command
   let searchCommand = new DelegateCommand<string>(fun (x) -> MessageBox.Show(x) |> ignore )

   //INotifyPropertyChanged interface
   interface INotifyPropertyChanged with
      member this.add_PropertyChanged(e) = event.Publish.AddHandler(e)
      member this.remove_PropertyChanged(e) = event.Publish.RemoveHandler(e)

   //Definition of the "Name" property
   member this.Name
        with get() = name
        and  set(v) =
             name <- v
             event.Trigger(this, new PropertyChangedEventArgs("Name"))

   //Definition of the "SearchCommand"
   member this.SearchCommand
        with get() = searchCommand

Cool, don’t you love this F# syntax? It’s so readable :)

Now we are ready to bind the MainPageVM to a xaml view inserting this simple code:

<StackPanel Orientation="Vertical">
     <!-- Example of binding to a F# ViewModel Command -->
     <Button Height="40" Content="Click me!"
           cmd:Click.Command="{Binding SearchCommand}"
           cmd:Click.CommandParameter="Hello from a ViewModel F# Command parameter"/>

     <!-- Example of binding to a F# ViewModel property -->
     <TextBlock Text="{Binding Name}" Height="40"/>
</StackPanel>

To make the ViewModel magic work, just assign the MainPageView DataContext with the F# ViewModel:

public MainPageView()
   {
       InitializeComponent();
       this.DataContext = new MainPageVM();
   }

The source code is available for download here.

New: updated the source code for Visual Studio 2010 Beta 2.

Happy Silverlighting!!


Mar 2 2009

The basic syntax of F#

Brian McNamara has posted two nice articles:


Dec 31 2008

Embedding a F# class library in a Silverlight 2 Application

Bill Reiss has written an excellent post about embedding F# class libraries in a C# Silverlight application. A must read!


Nov 9 2008

Building Azure worker roles using F#

In this post, Luke introduces the F# support for Azure services using the F# Templates and Samples for Windows Azure:

 

F# Visual Studio Templates

 


Nov 1 2008

An introduction to Microsoft F#

A great session by Luca Bolognese at PDC2008 is available here.

Update: the code is available in this post.


Sep 4 2008

F# September CTP available

Click here to read the post by Don Syme.


Jul 10 2008

Visual Studio, F# and scientific applications: VSLab

From http://www.codeplex.com/vslab:

Visual Studio Lab (VSLab) exploits the power of F# and its interactive top level to provide an interactive environment similar to MatLab and Mathematica, in which you can easily create Add-ins and interact dynamically with them inside Visual Studio. Moreover, since F# is a compiled language, the final code can be compiled as a standalone application.
Goal of the project is to provide the basic infrastructure to turn Visual Studio in VSLab, and a number of addins (called viewlets) used to show data and support development of scientific based applications.”

Useful links:


Oct 22 2007

Functional programming in .NET with F#

Take a look here for a list of resources about the F# language, a research project from Microsoft.

F# is a new “scripted, functional, imperative, object-oriented programming language“.

It seems to be very interesting!