Creating a Dropdown List in Xamarin.iOS

So in the Xamarin.iOS toolbox I was looking for a drop down list like I have used many times in windows and web applications.  I was surprised when I realized one doesn’t exist.

I ran across a couple great posts by Gooorack and ThirteenDaysAWeek on how to set this up.  While investigating, I did prefer the ListPickerViewModel published by jfoshee on Gist.

So I have put all these together into my own version, as well I want to display different text in the drop down list than what is “selected” and entered back into our textbox.  That is also why I liked the ListPickerViewModel that uses generics.

The example I have created is for a list of Provinces in Canada.  I want the drop down list to fully spell out all the provinces, but once selected I want the abbreviation to be entered into my textbox.

So to make this work you will need 3 pieces of code:

  1. Download the “ListPickerViewModel.cs” published by jfoshee on Gist.
  2. Have a data object created for you data.  I have attached this provinces example below or grab it from my Gist repo: https://gist.github.com/lfbarbieri/8c0b12193a758048f749
  3. Call this method “CreatePicker()” from ViewDidLoad() Method to create the picker.  Code is included below or available on Gist: https://gist.github.com/lfbarbieri/3f7194d8778c4c4999f6
Here is my “Provinces.cs” Data Model:
This is a pretty simple data model so not much to say here…

Below is the code for the CreatePicker() Method.  I have just included it as a private method within my ViewController class.

You will have to update a few lines based on your data model.

Line 5:  Create an instance of the ListPickerViewModel with your data type and instance of data list.
Line 22 & 23: Cast your picker item to your ListPickerViewModel and then specify the text to display from your selected item.
Line 38: Specify which property to compare against in your text box to select the right item in list.

That should be it, hope that helps you out!

Another Attempt at blogging

It has been quite a while since I have written a blog post but have been wanting to rejuvenate my blog as I start experimenting with some of the latest technology.  As well I keep reading from Scott Hanselman and John Sonmez on the importance of blogging.

I have been a long time BizTalk Developer and always interested in what it can do.  But recently I have really been intrigued with mobile development.  There is so much going on in this space.  I even tried learning Objective C a while ago but just couldn’t get into it.

But over the last few years I have been experimenting with the Xamarin tools.  I have actually been watching them since the Monotouch days at Novell.  For experienced C# developers there is no better way to develop Cross Platform applications for iOS, Android and Windows Phones.

An even newer area of interest that is picking up is in the area of Enterprise Mobile Platforms.  That is mobile applications that connect to your enterprise.  I have seen a few companies trying to get into this space.  Xamarin has also teamed up with SAP and Salesforce.com to provide ways to connect into the enterprise.

Another approach I want to look into is connecting Mobile Applications (developed using Xamarin) to the enterprise using BizTalk.  The best way of accomplishing this is by using Windows (Microsoft) Azure.

I hope to use this blog to document some of my learnings on this journey.