Programming, Xamarin

[SOLVED] Unable to cast object of type ‘Xamarin. Forms. Xaml. ElementNode’ to type ‘Xamarin. Forms. Xaml. ValueNode’.

When writing XAML for Xamarin Forms, you may across the error:

Unable to cast object of type 'Xamarin.Forms.Xaml.ElementNode' to type 'Xamarin.Forms.Xaml.ValueNode'

This is nearly always caused by assigning a value to an event in XAML, instead of specifying a method name.

A common example is:

<Switch Toggled="{Binding IsToggled}" />

Toggled is the name of an event. The property that was probably intended is called IsToggled.

<Switch IsToggled="{Binding IsToggled}" />

Android, Programming, Xamarin

[SOLVED] The BindableProperty “Triggers” is readonly

TLDR: When setting the Triggers property in XAML, use the actual type of the parent tag, not a supertype.

After recently updating Xamarin Forms from to, I started getting an InvalidOperationException: The BindableProperty "Triggers is readonly" inside InitializeComponent.

Unlike many problems, this was quite easy to track down. InitializeComponent errors are generally XAML, and in the page in question there was a single Trigger. In this case the solution was simple. The Trigger was on a custom Button type, but I was setting it specifically using Button.Triggers. Changing it to be the actual type fixed it.

So, I changed it from

    <DataTrigger ... />


    <DataTrigger ... />

I believe the original should be valid (and previously was) but the change is simple enough to not be a big problem.

Macs, Programming, Xamarin

Xamarin Forms coming to macOS

Since .NET and Xamarin were open sourced, I’ve kept a casual watch on their repositories for interesting things.

Recently I noticed this pull request “Change appearance of NSTabView”. This immediately stood out since NSTabView is an AppKit (i.e. macOS) API as opposed to a UIKit (i.e iOS) API. A quick read of the details and is indeed about some difference between NSTabView and UITabBar.

The pull request is targeting the branch “macos” and it seems it’s been in development since at least August 17th.

Android, Programming, Xamarin

[SOLVED] Xamarin Android and “–no-version-vectors”

TLDR: An error containing “–no-version-vectors” is probably fixed by updating your Android SDK Build Tools to at least 23.

I recently upgraded a project to the latest version of Xamarin Forms and got the following error:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 2. Output: ERROR: Unknown option '--no-version-vectors'

A quick $ grep -ri "no-version" . on the project revealed it was being used in a dependency brought in by the Forms update:

./packages/Xamarin.Android.Support.Vector.Drawable.23.3.0/build/Xamarin.Android.Support.Vector.Drawable.targets: $(AndroidResgenExtraArgs)--no-version-vectors

Long story short, this parameter is for the aapt tool in the Android SDK Build Tools from at least version 23. Updating through the Android SDK manager fixed it.