Back to School Part 2: Revenge of the Custom Bindings!

Back to School Part 2: Revenge of the Custom Bindings!

Late last summer I wrote a post on creating a custom bindable property using Xamarin.Forms. I titled it “Back to School” because I wrote it around … well … back to school time. Since then however, the Xamarin.Forms team has seen fit to deprecate the function I wrote about that creates the bindable property … and we’re still in the middle of summer! Ugh – it hasn’t even been a year! Well, I guess it’s only right of me to update a partially out of date post with the name “back to school” in it … So welcome to Back to School Part 2: Revenge of the Custom Bindings! I won’t go as in-depth as I did in Part 1, as the details I talk about in that post still stand – however, the API signature to create the binding has changed a bit, and that’s what I want to talk about here. The API Changes For the sake of example, I’m going to call the non-deprecated API the “new” API, although it has been around for a while. New API BindableProperty.Create (NEW) C# public static BindableProperty Create( string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, BindableProperty.ValidateValueDelegate validateValue = null, BindableProperty.BindingPropertyChangedDelegate propertyChanged = null, BindableProperty.BindingPropertyChangingDelegate propertyChanging = null, BindableProperty.CoerceValueDelegate coerceValue = null, BindableProperty.CreateDefaultValueDelegate defaultValueCreator = null); 12345678910111213  public static BindableProperty Create(    string propertyName,     Type returnType,     Type declaringType,     object defaultValue,     BindingMode defaultBindingMode = BindingMode.OneWay,     BindableProperty.ValidateValueDelegate validateValue = null,     BindableProperty.BindingPropertyChangedDelegate propertyChanged = null,     BindableProperty.BindingPropertyChangingDelegate propertyChanging = null,     BindableProperty.CoerceValueDelegate coerceValue = null,     BindableProperty.CreateDefaultValueDelegate defaultValueCreator = null);  Old API BindableProperty.Create (OLD) C# public static BindableProperty Create<TDeclarer, TPropertyType>( Expression<Func<TDeclarer, TPropertyType>> getter,...
View Model First Navigation Part 2 – The Devil’s In The Details

View Model First Navigation Part 2 – The Devil’s In The Details

The previous post on view model first navigation within Xamarin.Forms showed how to create a navigation service that associated a view to view model, kept track of those associations, provided functions to navigate between view models, and had the ability to instantiate a view based on which view model was being navigated to. In other words, it allowed navigation to a Xamarin.Forms.Page just by having a view model say it wanted to show another view model. That’s some pretty sweet stuff! The only problem with the navigation service, as implemented in the previous post, is that it didn’t work with master detail layouts. Not so sweet after all. Not to worry though – we’re going to right the ship and update the service so we can handle master detail pages in addition to tab and plain ‘ol navigation pages! Along the way we’re going to add some convenience functions to the navigation service and answer some common questions I have been getting about it. Before diving in too deep, if you haven’t already, please read the previous post on VM First navigation to get up to speed on what we’ll be talking about here. You can find the full implementation of the view model first navigation library on my GitHub here. Adding Master/Detail Navigation I have to say, adding the functionality to navigate between different detail pages from a master page proved to be more tricky than I had originally thought it would be. I thought I’d only have to find the MasterDetailPage as the Application.Current.MainPage, load up the view corresponding to the view model I wanted to show,...