💅 Extensions to make MvvmCross bindings more F#-ish
Install via NuGet using:
PM> Install-Package MvvmCross.FSharp
This is what bindings in F# look like:
let set = this.CreateBindingSet<MyView, MyViewModel>()
set
.Bind(source)
.To("MyList")
|> ignore
set
.Bind(source)
.For("SelectionChangedCommand")
.To("MyCommand")
|> ignore
set.Apply()
MvvmCross.FSharp® allows you to use quotations instead of strings for additional type safety:
let set = this.CreateBindingSet<MyView, MyViewModel>()
set
|> bind source
|> toExpression <@ this.ViewModel.MyList @>
|> ignore
set
|> bind source
|> forExpression <@ source.SelectionChangedCommand @>
|> toExpression <@ this.ViewModel.MyCommand @>
|> ignore
apply set
<|
ALSO PIPES |>
You can also use a DSL based on the operators:
|>>
: Thebind
operator>>
: Theto
operator>>>>
: Thefor
operator
Note that >>
= to = TWO characters. The same applies to the for
operator. Mnemonics FTW.
To use plain text instead of quotations when using the custom operators, replace the last >
with a .
. The number of characters in the operator remains the same, so it's still easy to remember.
Here's what the sample bindings would look like using the operator DSL:
let set = this.CreateBindingSet<MyView, MyViewModel>()
set |>> source >> <@ this.ViewModel.MyList @> |> ignore
set |>> source >>>> <@ source.SelectionChangedCommand @> >> <@ this.ViewModel.MyCommand @> |> ignore
apply set
A script scrapes the MvvmCross source code and generates a source file that provides type safe for
methods for each of the default-framework-provided bindings. This allows you to use bindings that are provided by the framework in a type safe way, like this:
open MvvmCross.FSharp.iOS.PropertyBinding
set
|> bind myButton
|> forTouchDown
|> toExpression <@ this.ViewModel.MyCommand @>
|> ignore
- Make the DSL even better®
- Turn the scrape script into a Type Provider