Saturday, April 30, 2016

A couple of odd questions in a Xamarin University course

These answers don't seem correct to me.  Anyone agree, disagree?




Sunday, April 24, 2016

Resolving common issues loading Xamarin Forms 2.0+ examples

After downloading and trying to run through a few Xamarin Forms demos, I've found that upgrading them to Forms 2.x seems to create errors.  Also you can encounter these errors even if you don't upgrade to the latest version of Forms. These issues will tend to focus on Android.

Issue 1: System.IO.FileNotFoundException: 

Could not load assembly 'Microsoft.Windows.Design.Extensibility, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?

Just delete the references which ends with *.Design. In my project it was: Xamarin.Forms.Core.Design,
Xamarin.Forms.Xaml.Design, 
Xamarin.Android.Support.Design.

See Also


Issue 2: Resources.String.ApplicationName and Resources.String.Hello are not defined

global::MYNAMESPACE.Resource.String.ApplicationName = global::MYNAMESPACE.Android.Resource.String.ApplicationName;

If you are getting an undefined error for either a resource string "Hello" or "ApplicationName" you have this issue.  These strings do not appear to be defined anywhere in the application code. Deleting it from the Resources.cs doesn't resolve the issue as it will just come back next time you build.
Fix it by running a clean and rebuild.

See also

Issue 3: Unsupported Android Target version.

If either the targeted version, or compile using version are set to a version of Android that your locally installed Android SDK doesn't support.  This is fixed either by installing that version using the Android SDK Manager or setting the Target and Compile versions in the Android project properties to something you do have locally installed.

 This App has an unsupported compile target.

Start the Android SDK Manager from Visual Studio

Or from Windows Start.

You can see here my current setup doesn't support Jelly Bean.  

In this case I chose to compile using Marshmallow, which is supported by my current setup.

Issue 4: Not configured to Deploy on Run (F5).

If you expect the App to compile, deploy and run when you press F5 or "Run" on the toolbar and it doesn't, then you'll need to adjust the build options.

You can see in this screen shot the Android project is not configured to deploy automatically when it is "Run".  Tick the box highlighted above, and you're set.



Wednesday, April 20, 2016

Auckland Xamarin Meet-Up Talk links

Steve Chadbourne – @stevechadbourne
Ben Rees @benrnz

Here some links to the tools Steve and I talked about tonight.  

Simple Xamarin Form Example: 
Learning Forms 
Gorilla Player
Open Source Xaml Viewer

Monday, April 18, 2016

Data Binding - The Awesome Sauce lavished onto Xamarin Forms

There are some great resources around introducing Data Binding for Xamarin Forms.  Here are some great posts I've come across that are worth reading and bookmarking.

For some background on getting started with Xamarin Forms. Check out the Xamarin guide here:
https://developer.xamarin.com/guides/xamarin-forms/

Xamarin have a solid section that gives a good start into learning XAML and Data Binding here:
https://developer.xamarin.com/guides/xamarin-forms/user-interface/xaml-basics/
Its definitely worth reading through all six sections.
Part 1. Getting Started with XAML
Part 2. Essential XAML Syntax
Part 3. XAML Markup Extensions
Part 4. Data Binding Basics
Part 5. From Data Binding to MVVM
Part 6. Compiling XAML

Data Binding Controls to each other to prevent/reduce writing code-behind.
https://blog.xamarin.com/advanced-data-binding-for-ios-android-and-windows/

Awesome Xamarin Forms How-To Commands

Recently read a great blog from David Britch giving a comprehensive guide to using commands with Xamarin Forms.

https://blog.xamarin.com/simplifying-events-with-commanding/

Fresh Essentials for Xamarin Forms

Michael Ridland has recently blogged about a nice light weight library of essential and commonly used converters, controls and utilities.

http://www.michaelridland.com/xamarin/freshessentials-for-xamarin-forms-the-must-have-nuget-for-forms/

Saturday, April 9, 2016

Simple Xamarin Forms Demo App

A Simple Xamarin Forms Sample App


Recently I presented a short Xamarin Forms introduction.  It was only a short 30min taster, but I wanted to ensure I was showing something a little deeper than a simple "Hello World" App.  I personally find those kind of demo's too basic and not enough to get a taste of how using a technology is going to suit real world work.

Here's the App I built for the demo:

https://github.com/Benrnz/CorporateBsGenerator


Demo points

  1. Solution structure of a Xamarin Forms App.
  2. Entry point - how does it start and choose the first Xaml page?
  3. Anatomy of a Xaml page.
  4. Xaml Basics
    1. Root elements, in this case a ContentPage. Other options are MasterDetailPage, TabbedPage, and NavigationPage.
    2. Setting Page Padding to different values for each platform.
    3. Layout Controls: In this case we're using a AbsoluteLayout and a StackLayout.  Another common Layout is Grid.
    4. Labels, Styles, and basic value DataBinding.
    5. Using different buttons for iOS and Android.  The Material Design Floating Action Button.
    6. Binding can be used for more than value binding. The FAB has a bound reference to the ListView.
  5. Code Behind
    1. Great to get started
    2. Event Handlers
    3. Best Practice - Code behind doesn't scale well.  The MVVM pattern.
  6. A look at more advanced customisation for Android. A Custom Renderer to create a Floating Action Button.
  7. Tooling - What do we need to develop and test an App?

Sunday, April 3, 2016

Floating Action Button in Xamarin Forms

I'm loving experimenting with Xamarin Forms at the moment. So when I wanted to include a Floating Action Button (FAB) in Android versions of a Forms App, I naturally wanted to try to get this working with Forms first.  I realise you can use Xamarin Native Android views in a Forms App, but I enjoy XAML and creating reusable controls.

My first port of call was James Montemagno's GitHub and blog and found his examples for a FAB.

https://github.com/jamesmontemagno/FloatingActionButton-for-Xamarin.Android
He does mention he ported this code from: https://github.com/makovkastar/FloatingActionButton

This looks perfect, but I wanted to improve the Forms example to be mostly XAML based and try to best encapsulate the events into the FAB control to minimise the amount of work the consuming developer has to do.

Here's my code so far.
https://github.com/Benrnz/XamlFloatingActionButton

Its far from perfect, but works great.  Be aware however, that if your ObservableCollection has duplicate values in it, the FAB will exhibit unexpected hide/show behaviour.

Here's what I ended up with in my XAML:

  <AbsoluteLayout VerticalOptions="FillAndExpand"  
           HorizontalOptions="FillAndExpand">  
     <StackLayout AbsoluteLayout.LayoutFlags="All"  
            AbsoluteLayout.LayoutBounds="0,0,1,1">  
       <Label Text="FAB Test 1"  
           VerticalOptions="Center"  
           HorizontalOptions="Center" />  
       <ListView x:Name="MainList"   
            ItemsSource="{Binding MyItems}"  
            VerticalOptions="FillAndExpand"/>  
     </StackLayout>  
     <fabTest1:FloatingActionButtonView x:Name="Fab"   
                       AbsoluteLayout.LayoutFlags="PositionProportional"   
                       AbsoluteLayout.LayoutBounds="1,1,AutoSize,AutoSize"  
                       ImageName="ic_add.png"  
                       ColorNormal="#ff3498db"  
                       ColorPressed="Black"  
                       ColorRipple="#ff3498db"  
                       Command="{Binding FabExecuteCommand}"  
                       ParentList="{Binding Source={x:Reference MainList}, Path=.}"/>  
   </AbsoluteLayout>  

Microsoft announces new licencing for Xamarin!




Since Microsoft bought Xamarin and the deal was officially signed and closed about two weeks ago, Microsoft have announced their intentions to open source and make Xamarin free.

Visual Studio Community edition (the free edition) will also have access but not to all features.
This will include:

  • Xamarin Studio (Mac and Windows version)
  • Xamarin Platform for iOS, Android and Windows, for small teams and non-Enterprise organisations.  Enterprise is defined as organisations earning more then one million US Dollars per annum.
  • Check out this blog from https://blog.xamarin.com/xamarin-for-all/
Writing an App for any platform using Xamarin is now totally open source!


Check out the actual //Build 2016 announcement by Scott Guthrie:
https://www.youtube.com/watch?v=WC7ijoFzjEg
18:35

Test Cloud will continue to be a paid product with several tiers although Enterprise MSDN subscribers will get a 25% discount.

Xamarin Insights will merge with Microsoft's HockeyApp over time.  Right now Insights has features that Hockey does not yet support.

Some level of Xamarin University will be included for MSDN Professional and Enterprise subscribers, although this isn't clear yet.

Check out https://store.xamarin.com/ for latest details.