All posts in Xamarin Forms

I was working on DayTickler and authentication when the latest Azure Mobile Client was released. Being fearless, i decided to upgrade.

Turns out the new version of the nuget doesn`t support pcl, but netstandard. No problem, let`s upgrade everything to netstandard, i need it for things like the latest AutoMapper anyways.

NetStandard is the new name for portable libraries. They are not built X time for each platform but offer binary compatibility for each platform. For example, uap10 implements netstandard 1.4, meaning that any UWP project can target libraries of type netstandard 1.4 because it provides and implementation of all the 1.4 level api…

It`s really complicated, but i always go back to this post, mainly for this table :

.NET Standard 1.0 1.1 1.2 1.3 1.4 1.5 1.6 2.0
.NET Core 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0
.NET Framework (with tooling 1.0) 4.5 4.5 4.5.1 4.6 4.6.1 4.6.2
.NET Framework (with tooling 2.0 preview) 4.5 4.5 4.5.1 4.6 4.6.1 4.6.1 4.6.1 4.6.1
Mono 4.6 4.6 4.6 4.6 4.6 4.6 4.6 vNext
Xamarin.iOS 10.0 10.0 10.0 10.0 10.0 10.0 10.0 vNext
Xamarin.Android 7.0 7.0 7.0 7.0 7.0 7.0 7.0 vNext
Universal Windows Platform 10.0 10.0 10.0 10.0 10.0 vNext vNext vNext
Windows 8.0 8.0 8.1
Windows Phone 8.1 8.1 8.1
Windows Phone Silverlight 8.0

 

Also, if, along the way, you wish to include non netstandard libraries in your netstandard library,  you can modify your project.json like this :

“frameworks”: {
“netstandard1.4”: {
“imports”: [ “portable-net45+win8+wpa81” ]
}
}

It helps !

I’ve spent a lot of time trying to get non modal navigation working on DayTickler.

Here’s the thing – it is complicated to test on every platform and ensure it works correctly when we want a MasterDetailPage…

Here is my recipe :

public class App : Application
 {
   public App()
   {
     // The root page of your application
     MainPage = new MasterDetailPage()
     {
       Detail = new NavigationPage(new ContentPage()
       {
         BackgroundColor = Color.Green,
         Title = "detail title",
         Icon = "hamburger.png",
         Content = new StackLayout
         {
           VerticalOptions = LayoutOptions.Center,
           Children = {
             new Button {
               HorizontalOptions = LayoutOptions.Center,
               Text = "push new page!",
               Command = new Command((t) => { ((MasterDetailPage)App.Current.MainPage).Detail.Navigation.PushAsync(new ContentPage() { BackgroundColor = Color.Lime }); })
             }
           }
         }
       }),
       Master = new ContentPage()
       {
         Icon = "hamburger.png",
         BackgroundColor = Color.Pink,
         Title = "master title",
         Content = new StackLayout
         {
           VerticalOptions = LayoutOptions.Center,
           Children = {
             new Button {
               HorizontalOptions = LayoutOptions.Center,
               Text = "hamburger",
               Command = new Command((t) => { })
             }
           }
         }
       },
     }; 
   }

As you can see, the trick when wanting non modal navigation and using a MasterDetailPage is to not have the MainPage of your app be a NavigationPage, but each of the details page. Then, you just have to be smart about not using the Navigation property on the App’s MainPage but on the detail page.

Well, it’s 2016 and technology doesn’t stop advancing.

A couple of months ago, I though Xamarin was the best platform for creating cross platform apps from the same (or mostly same) source code. From a technology standpoint, Xamarin offers the mechanisms to use all of my Visual Studio and .NET skills to build cross platform apps. All I needed was a MacMini hidden in my basement to do compilations. Let’s not forget their Xamarin Forms technology that gives you a single thing to learn to build user interfaces for the three major platforms.

I built a lot of web apps, some with Angular or other SPA frameworks, but to be honest nothing made it worthwhile. Plus the fact that I find Angular soooo complicated to learn.

Fast forwards to today. The web has advanced, and all new Windows machines have Edge, a great browser without the need to install something else such as Chrome. Angular 2 is in beta, as well as Aurelia: new SPA frameworks that embrace the latest advances in html5. Add to that the new web UI frameworks (e.g. Framework7) that skin web apps with the same look and feel as native apps on IOS and Android (I guess UWP support will be trivial to add to these frameworks). I’ve built an Aurelia app with these technologies, and I have about 10 times less code to do the same thing as with Xamarin Forms. Coupled with ManifoldJS, I can package a web site to a mobile app…

Now where does Xamarin Forms stand in this new world ? I believe the cross platform technology for normal, business apps has a very short future ahead of it. As some of you who follow what I do know – it’s full of bugs which I keep on declaring and there are always a regression here and there. I still believe in the technology, but I believe Xamarin needs to open source it’s Xamarin Forms project. In a matter of weeks I am certain the bugs will disappear and a bunch of new functionality will emerge. That will make a difference. I believe Xamarin’s value proposition is in reusing .net skills and know how, not an cross platform API. Besides, Xamarin Forms is useless without the core Xamarin engine to generate the IOS and Android apps.

Now for my predications. In 2016, I will only start new projects with web technologies. If Xamarin Forms is open sourced, I will consider it again. Obviously, project specifics might make me use one or the other whatever my current preferences are…

 

 

 

I was playing around with Xamarin Forms, and ran into a small hiccup :  Let’s say I have a list, and one particular item is disabled – what do I do ?

It’s easy to add a “Disabled” property to the associated ViewModel, and in the associated command check if it is disabled and if so, just return. But how do alter the visual state based on this property ?

A little searching brought me to this excellent article on http://pause.coffee/blog/ which gave me the answer.

I simply created a small class named GreyLabelIfDisabeldBehavior and here is it’s code:

    public class GreyLabelIfDisabledBehavior
    {
        public static readonly BindableProperty DisabledProperty = BindableProperty.CreateAttached<GreyLabelIfDisabledBehavior, bool>(
               bindable => GreyLabelIfDisabledBehavior.GetDisabled(bindable),
               false, /* default value */
               BindingMode.OneWay,
               null,
               (b, o, n) => GreyLabelIfDisabledBehavior.OnDisabledChanged(b, o, n),
               null,
               null);

        public static bool GetDisabled(BindableObject bo)
        {
            return (bool)bo.GetValue(GreyLabelIfDisabledBehavior.DisabledProperty);
        }

        public static void SetDisabled(BindableObject bo, Command value)
        {
            bo.SetValue(GreyLabelIfDisabledBehavior.DisabledProperty, value);
        }

        public static void OnDisabledChanged(BindableObject bo, bool oldValue, bool newValue)
        {
            if (oldValue != newValue)
            {
                var color = ColorEx.Render("foreground");
                if (newValue)
                    color = ColorEx.Render("gray");
                (bo as Label).TextColor = color;
            }
        }
    }

After that, it was a simple case of using the new feature in XAML like this:
<Label Text={Binding Title} customControls:GreyLabelIfDisabledBehavior.Disabled={Binding Disabled}/>