Bug 28521 - Xaml Bindings do not work for my custom controls, no matter what I do
Summary: Xaml Bindings do not work for my custom controls, no matter what I do
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-29 01:38 UTC by George Cook
Modified: 2015-06-05 12:43 UTC (History)
5 users (show)

Tags: docs ac
Is this bug a regression?: ---
Last known good build:


Attachments
working project showing how xaml bindings do not work in my custom controls (4.12 MB, application/zip)
2015-03-29 01:38 UTC, George Cook
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description George Cook 2015-03-29 01:38:58 UTC
Created attachment 10544 [details]
working project showing how xaml bindings do not work in my custom controls

I've spent hours (nearly 10 hours now), going through the internet and trying just about every single example I can find, and no matter what I do, I can't get any bindings I create in custom controls to work.

i.e.

	<local:EmergencyLabel Text="Hello there, this is a very long string" Color="Red" />

namespace BindingTest
{
	public class EmergencyLabel : Label
	{
		public static readonly BindableProperty ColorProperty =
			BindableProperty.Create<EmergencyLabel, Color> (
				p => p.Color, Color.Red);

		public Color Color {
			get { return (Color)GetValue (ColorProperty); }
			set { SetValue (ColorProperty, value); }
		}
	}
}



The setter is never ever called.

I've also attached a project that explains the issue too. 

I'm meant to be presenting to my company about the benefits of Xmaarin next week, and I'll be missing that deadline as one of the main benefits (binding) doesn't work for me, which is also robbing time from doing more dev to show off the cool features of it.
Comment 1 George Cook 2015-03-29 09:44:12 UTC
With much expanation from adam Kemp in the forum I got it working.

This bug should change to : "add more documentation for binding mechanism". I couldn't find anything documenting the process of creating bindings properly incode. Furthermore, Adam reverese compiled the dlls to find out htat there is a constraint on naming for the properties.

Things like this Must be documented - I lost 10 hours trying to get this to work. I'm sure other devs will have equally as frustrating times with it.
Comment 2 Rajneesh Kumar 2015-05-04 08:58:27 UTC
I have checked this issue and able to reproduce this issue. To reproduce this issue I have followed the steps mentioned below:

1. Open attached test case in XS.
2. Build and deploy app on emulator.
3. Click on button "Manually Set space".
4. Observed that screen colour changed to green.
5. Click on button "test".
6. Observed that the screen colour does't changed.

Screencast: http://www.screencast.com/t/Qu22Bax2dM

Ide Logs: https://gist.github.com/Rajneesh360Logica/c7724d2fa588e4994370
Build output: https://gist.github.com/Rajneesh360Logica/50809fe31b73a6fe998b
Application Output: https://gist.github.com/Rajneesh360Logica/3177080f322ddaf03a9a

Environment Info:

Xamarin.forms Version: 1.4.3.6358-pre2

=== Xamarin Studio ===

Version 5.9 (build 459)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 4.0.1 ((detached/5a0b19f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010024

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.10.1.11 (Business Edition)
Hash: d153c60
Branch: master
Build date: 2015-05-01 11:26:36-0400

=== Xamarin.Android ===

Version: 5.1.0.115 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.1.21 (Business Edition)

=== Build Information ===

Release ID: 509000459
Git revision: 84bacb5e3f9be4e7b5743c7e58a22cc58007fa5f
Build date: 2015-04-30 04:20:30-04
Xamarin addins: 0e5c28beb42ad379214edfb60ddd18acdbe8fd0c

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 3 Eric Maupin 2015-06-05 12:43:08 UTC
As it seems you've found out, XAML will use the bindable property to call SetValue on the object. For callbacks you need to use the delegate argument in the BP create method, as your setter will only ever be called when set directly.