Xamarin 3 F# Awesomeness
@ 7sharp9 · Wednesday, May 28, 2014 · 2 minute read · Update at May 28, 2014

With the release of Xamarin 3 there is a swathe of new features to the platform, but obviously the most important one is obviously F# support is now included by default in Xamarin Studio so there is no escape from the awesomeness of F#!

So what else have we got, well loads of other goodies too like Xamarin Designer for iOS, Xamarin.Forms, Major IDE enhancements, Improved code sharing with PCL and Shared projects, and BCL Documentation. You can see the release blog post here: announcing Xamarin 3

There are tons of things I could show you, but for this post lets have a quick look at Xamarin.Forms

Xamarin.Forms

So what is Xamarin.Forms? Well to paraphrase the Xamarin blurb a little bit:

Build native UIs for iOS, Android and Windows Phone from a single, shared codebase. Xamarin.Forms pages represent single screens within an app.

Pages contain layouts, buttons, labels, lists, and other common controls. Connect these controls to shared backend code and you get fully native iOS, Android, and Windows Phone apps built entirely with shared code.

So as this just a whistle-stop post I’ll quickly show you the code.:

let profilePage = 
   ContentPage(Title="Profile",
               Icon="Profile.png",
               Content=StackLayout.Create(
                           [ Entry (Placeholder="Username") 
                             Entry (Placeholder="Password", IsPassword=true)
                             Button (Text="Login",
                                     TextColor=Color.White, 
                                     BackgroundColor=Color.FromHex "77D065") ], 
                             spacing=20.0,
                             padding=thickness 50.0,
                             verticalOptions=LayoutOptions.Center))
                        
let settingsPage = ContentPage(Title="Settings", Icon="Settings.png")

let mainPage = TabbedPage.create [profilePage;settingsPage]

The result is a nice cross platform UI thats easy to build and maintain, sweet!

You can see by the code thats there are several components at play but it’s very easy to see how the code relates to the UI layout. A stack layout with two Entry types followed by a Button. You can also see at the bottom that there is a TabbedPage comprising of the profilePage and the settingPage.

Nice and easy!

OK, thats it for now, but next time I’ll be delving in a little deeper and showing you exactly how to build a PCL backed F# app over multiple platforms.

Until next time!

Dave Thomas
7sharp9's blog
A cup of tea would restore my normality. - Douglas Adams
agents ast async concurrency csharp elixir elm fable fsharp functional-programming fuse games ios javascript mac mailboxprocessor metaprogramming microsoft mono monodevelop monogame monotouch myriad performance quotations running sockets threading tpl tpl-dataflow typeproviders videos xamarin youtube

© 2011 - 2020 7sharp9

Powered by Hugo with theme Dream.

About Me

Hi, my name is Dave Thomas and Im a software engineer from the Uk. I work primarily in F# but also like to tinker with pretty much any interesting language. Im drawn to more functional languages like F#, Swift and Rust.

Have questions or suggestions? Feel free to ask me on Twitter.

Thanks for reading!